[Lldb-commits] [lldb] 51117e3 - [lldb][NFC] Remove unused custom reimplementation of realpath for Windows

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 11 01:05:05 PDT 2020


Author: Raphael Isemann
Date: 2020-08-11T10:04:42+02:00
New Revision: 51117e3c51754f3732ee34758310a0abc6fd3b75

URL: https://github.com/llvm/llvm-project/commit/51117e3c51754f3732ee34758310a0abc6fd3b75
DIFF: https://github.com/llvm/llvm-project/commit/51117e3c51754f3732ee34758310a0abc6fd3b75.diff

LOG: [lldb][NFC] Remove unused custom reimplementation of realpath for Windows

No one is calling this function it seems and according to
https://bugs.llvm.org/show_bug.cgi?id=47088 this can leak memory, so let's just
remove it:

Quote from the bug report:
> Before return on line 146, the memory allocated on line 130 is not freed.

Reviewed By: amccarth

Differential Revision: https://reviews.llvm.org/D85633

Added: 
    

Modified: 
    lldb/include/lldb/Host/windows/PosixApi.h
    lldb/source/Host/windows/Windows.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/windows/PosixApi.h b/lldb/include/lldb/Host/windows/PosixApi.h
index a4c3dcdbc521..aee7394b03e3 100644
--- a/lldb/include/lldb/Host/windows/PosixApi.h
+++ b/lldb/include/lldb/Host/windows/PosixApi.h
@@ -98,7 +98,6 @@ typedef uint32_t pid_t;
 // custom implementations.
 int vasprintf(char **ret, const char *fmt, va_list ap);
 char *strcasestr(const char *s, const char *find);
-char *realpath(const char *name, char *resolved);
 
 #ifdef _MSC_VER
 

diff  --git a/lldb/source/Host/windows/Windows.cpp b/lldb/source/Host/windows/Windows.cpp
index 32129bb6d1e5..172ea29107d3 100644
--- a/lldb/source/Host/windows/Windows.cpp
+++ b/lldb/source/Host/windows/Windows.cpp
@@ -82,89 +82,6 @@ char *strcasestr(const char *s, const char *find) {
   return const_cast<char *>(s);
 }
 
-char *realpath(const char *name, char *resolved) {
-  char *retname = NULL;
-
-  /* SUSv3 says we must set `errno = EINVAL', and return NULL,
-  * if `name' is passed as a NULL pointer.
-  */
-  if (name == NULL) {
-    errno = EINVAL;
-    return NULL;
-  }
-
-  /* Otherwise, `name' must refer to a readable filesystem object,
-  * if we are going to resolve its absolute path name.
-  */
-  wchar_t wideNameBuffer[PATH_MAX];
-  wchar_t *wideName = wideNameBuffer;
-  if (!utf8ToWide(name, wideName, PATH_MAX)) {
-    errno = EINVAL;
-    return NULL;
-  }
-
-  if (_waccess(wideName, 4) != 0)
-    return NULL;
-
-  /* If `name' didn't point to an existing entity,
-  * then we don't get to here; we simply fall past this block,
-  * returning NULL, with `errno' appropriately set by `access'.
-  *
-  * When we _do_ get to here, then we can use `_fullpath' to
-  * resolve the full path for `name' into `resolved', but first,
-  * check that we have a suitable buffer, in which to return it.
-  */
-
-  if ((retname = resolved) == NULL) {
-    /* Caller didn't give us a buffer, so we'll exercise the
-    * option granted by SUSv3, and allocate one.
-    *
-    * `_fullpath' would do this for us, but it uses `malloc', and
-    * Microsoft's implementation doesn't set `errno' on failure.
-    * If we don't do this explicitly ourselves, then we will not
-    * know if `_fullpath' fails on `malloc' failure, or for some
-    * other reason, and we want to set `errno = ENOMEM' for the
-    * `malloc' failure case.
-    */
-
-    retname = (char *)malloc(PATH_MAX);
-    if (retname == NULL) {
-      errno = ENOMEM;
-      return NULL;
-    }
-  }
-
-  /* Otherwise, when we do have a valid buffer,
-  * `_fullpath' should only fail if the path name is too long.
-  */
-
-  wchar_t wideFullPathBuffer[PATH_MAX];
-  wchar_t *wideFullPath;
-  if ((wideFullPath = _wfullpath(wideFullPathBuffer, wideName, PATH_MAX)) ==
-      NULL) {
-    errno = ENAMETOOLONG;
-    return NULL;
-  }
-
-  // Do a LongPath<->ShortPath roundtrip so that case is resolved by OS
-  // FIXME: Check for failure
-  size_t initialLength = wcslen(wideFullPath);
-  GetShortPathNameW(wideFullPath, wideNameBuffer, PATH_MAX);
-  GetLongPathNameW(wideNameBuffer, wideFullPathBuffer, initialLength + 1);
-
-  // Convert back to UTF-8
-  if (!wideToUtf8(wideFullPathBuffer, retname, PATH_MAX)) {
-    errno = EINVAL;
-    return NULL;
-  }
-
-  // Force drive to be upper case
-  if (retname[1] == ':')
-    retname[0] = toupper(retname[0]);
-
-  return retname;
-}
-
 #ifdef _MSC_VER
 
 char *basename(char *path) {


        


More information about the lldb-commits mailing list