[PATCH] wbemprox: fix memory leaks (Coverity)

Marcus Meissner marcus at jet.franken.de
Sat Jun 15 02:38:02 CDT 2013


1030109 Resource leak
1030112 Resource leak
	Just allocate dirstack a bit later to avoid the leak.

1030111 Resource leak
	there were some continues in the loop were glob would be overwritten on next loop

1030110 Resource leak
	added missing FindClose

Ciao, Marcus
---
 dlls/wbemprox/builtin.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c
index d90165f..852df0a 100644
--- a/dlls/wbemprox/builtin.c
+++ b/dlls/wbemprox/builtin.c
@@ -1273,11 +1273,12 @@ static enum fill_status fill_directory( struct table *table, const struct expr *
     DWORD drives = GetLogicalDrives();
     WIN32_FIND_DATAW data;
     HANDLE handle;
-    struct dirstack *dirstack = alloc_dirstack(2);
+    struct dirstack *dirstack;
     enum fill_status status = FILL_STATUS_UNFILTERED;
 
     if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
+    dirstack = alloc_dirstack(2);
     for (i = 0; i < sizeof(drives); i++)
     {
         if (!(drives & (1 << i))) continue;
@@ -1298,11 +1299,13 @@ static enum fill_status fill_directory( struct table *table, const struct expr *
             }
             if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
             {
+                heap_free(glob);
                 do
                 {
                     if (!resize_table( table, row + 1, sizeof(*rec) ))
                     {
                         status = FILL_STATUS_FAILED;
+                        FindClose( handle );
                         goto done;
                     }
                     if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
@@ -1336,16 +1339,16 @@ static enum fill_status fill_directory( struct table *table, const struct expr *
                 }
                 while (FindNextFileW( handle, &data ));
                 FindClose( handle );
-            }
+            } else
+                heap_free(glob);
+
             if (!peek_dir( dirstack )) break;
-            heap_free( glob );
             heap_free( path );
         }
     }
 
 done:
     free_dirstack( dirstack );
-    heap_free( glob );
     heap_free( path );
 
     TRACE("created %u rows\n", row);
-- 
1.7.10.4




More information about the wine-patches mailing list