diff --git a/dlls/netapi32/apibuf.c b/dlls/netapi32/apibuf.c index 010409503eb..6a8b8db1bde 100644 --- a/dlls/netapi32/apibuf.c +++ b/dlls/netapi32/apibuf.c @@ -62,7 +62,10 @@ NET_API_STATUS WINAPI NetApiBufferReallocate(LPVOID OldBuffer, DWORD NewByteCoun TRACE("(%p, %ld, %p)\n", OldBuffer, NewByteCount, NewBuffer); if (NewByteCount) { - *NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount); + if (OldBuffer) + *NewBuffer = HeapReAlloc(GetProcessHeap(), 0, OldBuffer, NewByteCount); + else + *NewBuffer = HeapAlloc(GetProcessHeap(), 0, NewByteCount); return *NewBuffer ? NERR_Success : GetLastError(); } else diff --git a/dlls/netapi32/tests/apibuf.c b/dlls/netapi32/tests/apibuf.c index 03f25543b11..d4adbbb0339 100644 --- a/dlls/netapi32/tests/apibuf.c +++ b/dlls/netapi32/tests/apibuf.c @@ -64,8 +64,8 @@ void run_apibuf_tests(void) ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n"); /* border reallocate cases */ - ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) != NERR_Success, "(Re)allocated\n"); - ok(p == NULL, "Some memory got allocated\n"); + ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n"); + ok(p != NULL, "No memory got allocated\n"); ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved\n"); ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed\n"); ok(p == NULL, "Pointer not cleared\n");