[PATCH] advapi32/tests: Fix memory leaks in test_performance_keys (Coverity)

Alex Henrie alexhenrie24 at gmail.com
Sun Dec 26 22:01:19 CST 2021


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/advapi32/tests/registry.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index ca371f73d65..ecddfe647c2 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -3675,7 +3675,7 @@ static void test_performance_keys(void)
     LARGE_INTEGER perftime1, perftime2, systime1, systime2, freq;
     WCHAR sysname[MAX_COMPUTERNAME_LENGTH + 1];
     unsigned int buffer_size = 1024 * 1024;
-    void *buffer, *bufferW;
+    void *buffer, *bufferW = NULL;
     PERF_DATA_BLOCK *data;
     union
     {
@@ -3804,7 +3804,7 @@ static void test_performance_keys(void)
         ok(!ret, "got %u\n", ret);
         ok(size > 0, "got size %u\n", size);
 
-        bufferW = malloc(size);
+        bufferW = realloc(bufferW, size);
 
         type = 0xdeadbeef;
         ret = RegQueryValueExW(keys[i], L"cOuNtEr", NULL, &type, bufferW, &size);
@@ -3843,7 +3843,7 @@ static void test_performance_keys(void)
         ok(!ret, "got %u\n", ret);
         ok(size > 0, "got size %u\n", size);
 
-        bufferW = malloc(size);
+        bufferW = realloc(bufferW, size);
 
         type = 0xdeadbeef;
         ret = RegQueryValueExW(keys[i], L"hElP", NULL, &type, bufferW, &size);
@@ -3922,6 +3922,7 @@ static void test_performance_keys(void)
     todo_wine ok(ret == ERROR_NO_MORE_ITEMS, "got %u\n", ret);
 
     free(buffer);
+    free(bufferW);
 }
 
 static void test_perflib_key(void)
-- 
2.34.1




More information about the wine-devel mailing list