]> wimlib.net Git - wimlib/commitdiff
win32_get_short_name(): Add missing FindClose
authorEric Biggers <ebiggers3@gmail.com>
Thu, 25 Apr 2013 04:22:30 +0000 (23:22 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 25 Apr 2013 04:22:30 +0000 (23:22 -0500)
src/win32.c

index 1b2aeffe597189f77396dd2a864a5ec54262c943..c36b13ae8593d106080d34915ed8b712c4b9764a 100644 (file)
@@ -394,22 +394,31 @@ static int
 win32_get_short_name(struct wim_dentry *dentry, const wchar_t *path)
 {
        WIN32_FIND_DATAW dat;
 win32_get_short_name(struct wim_dentry *dentry, const wchar_t *path)
 {
        WIN32_FIND_DATAW dat;
-       if (FindFirstFileW(path, &dat) && dat.cAlternateFileName[0] != L'\0') {
-               DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName);
-               size_t short_name_nbytes = wcslen(dat.cAlternateFileName) *
-                                          sizeof(wchar_t);
-               size_t n = short_name_nbytes + sizeof(wchar_t);
-               dentry->short_name = MALLOC(n);
-               if (!dentry->short_name)
-                       return WIMLIB_ERR_NOMEM;
-               memcpy(dentry->short_name, dat.cAlternateFileName, n);
-               dentry->short_name_nbytes = short_name_nbytes;
-       }
+       HANDLE hFind;
+       int ret = 0;
+
        /* If we can't read the short filename for some reason, we just ignore
         * the error and assume the file has no short name.  I don't think this
         * should be an issue, since the short names are essentially obsolete
         * anyway. */
        /* If we can't read the short filename for some reason, we just ignore
         * the error and assume the file has no short name.  I don't think this
         * should be an issue, since the short names are essentially obsolete
         * anyway. */
-       return 0;
+       hFind = FindFirstFileW(path, &dat);
+       if (hFind != INVALID_HANDLE_VALUE) {
+               if (dat.cAlternateFileName[0] != L'\0') {
+                       DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName);
+                       size_t short_name_nbytes = wcslen(dat.cAlternateFileName) *
+                                                  sizeof(wchar_t);
+                       size_t n = short_name_nbytes + sizeof(wchar_t);
+                       dentry->short_name = MALLOC(n);
+                       if (dentry->short_name) {
+                               memcpy(dentry->short_name, dat.cAlternateFileName, n);
+                               dentry->short_name_nbytes = short_name_nbytes;
+                       } else {
+                               ret = WIMLIB_ERR_NOMEM;
+                       }
+               }
+               FindClose(hFind);
+       }
+       return ret;
 }
 
 static int
 }
 
 static int