netapi32: NetApiBufferReallocate fixes & tests

Dimitrie O. Paun dpaun at rogers.com
Wed Dec 3 10:45:35 CST 2003


On November 26, 2003 07:40 pm, Juan Lang wrote:
> NetApiBufferReallocate:
> - does not allocate memory when NULL is the original
> pointer passed in
> - frees memory when the new size is 0

Thanks Juan,
Here's the resulting patch.

ChangeLog
    Fix NetApiBufferReallocate and add a few tests for the border
    cases (thanks to Juan Lang for clarifications).

Index: dlls/netapi32/apibuf.c
===================================================================
RCS file: /var/cvs/wine/dlls/netapi32/apibuf.c,v
retrieving revision 1.3
diff -u -r1.3 apibuf.c
--- dlls/netapi32/apibuf.c	5 Sep 2003 23:08:35 -0000	1.3
+++ dlls/netapi32/apibuf.c	3 Dec 2003 16:41:24 -0000
@@ -60,11 +60,17 @@
                                              LPVOID* NewBuffer)
 {
     TRACE("(%p, %ld, %p)\n", OldBuffer, NewByteCount, NewBuffer);
-    *NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount);
-    if (*NewBuffer)
-        return NERR_Success;
-    else
-        return GetLastError();
+    if (NewByteCount) 
+    {
+	*NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount);
+	return *NewBuffer ? NERR_Success : GetLastError();
+    } 
+    else 
+    {
+	if (!HeapFree(GetProcessHeap(), 0, OldBuffer)) return GetLastError();
+	*NewBuffer = 0;
+	return NERR_Success;
+    }
 }
 
 /************************************************************
Index: dlls/netapi32/tests/apibuf.c
===================================================================
RCS file: /var/cvs/wine/dlls/netapi32/tests/apibuf.c,v
retrieving revision 1.3
diff -u -r1.3 apibuf.c
--- dlls/netapi32/tests/apibuf.c	5 Sep 2003 23:08:35 -0000	1.3
+++ dlls/netapi32/tests/apibuf.c	3 Dec 2003 16:38:01 -0000
@@ -63,7 +63,14 @@
     ok(dwSize >= 0, "The size");
     ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
 
-   /* 0-length buffer */
+    /* border reallocate cases */
+    ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) != NERR_Success, "(Re)allocated");
+    ok(p == NULL, "Some memory got allocated");
+    ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved");
+    ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed");
+    ok(p == NULL, "Pointer not cleared");
+    
+    /* 0-length buffer */
     ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
        "Reserved memory");
     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");


-- 
Dimi.




More information about the wine-patches mailing list