netapi32: Set the buffer to NULL in NetApiBufferFree

Reece Dunn msclrhd at googlemail.com
Thu Jun 26 10:35:21 CDT 2008


2008/6/26 Kai Blin <kai.blin at gmail.com>:
> On Thursday 26 June 2008 16:34:51 you wrote:
>
>> @@ -52,6 +52,7 @@ NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
>>  {
>>      TRACE("(%p)\n", Buffer);
>>      HeapFree(GetProcessHeap(), 0, Buffer);
>> +    Buffer = NULL;
>>      return NERR_Success;
>>  }
>>
>> I don't get it.  How does setting a local variable to NULL avoid a
>> warning about freeing it twice?
>
> The trick is the test code.
>
> From dlls/netapi32/tests/apibuf.c, lines 44-58
> ...
>
>    ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
>
>    /* test errors handling */
>    ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n"); <-- valgrind warning
>
> Which is to be expected. HeapFree on a NULL pointer doesn't hurt, though. As
> this test seems to work on Windows, that seemed like the quickest fix.

The fix should be
    *Buffer = NULL;
not
    Buffer = NULL;
since p (in the tests) would still be valid after the NetApiBufferFree call.

NOTE: You'll need to add a test for NetApiBufferFree(NULL) if there
isn't one to see if null-pointer dereferencing should be checked
against.

There should be ok(p) or ok(!p) tests to check if this is being set to
NULL on Windows after the call.

Also, GetLastError calls may be needed.

- Reece



More information about the wine-devel mailing list