mirror of
https://github.com/reactos/reactos.git
synced 2025-04-27 09:00:27 +00:00
[APPHELP_APITEST] Properly handle a couple 'malloc()/free()' (#2898)
Detected by Cppcheck: memleak, redundantAssignment.
Addendum to 78280ad2
(r71226).
This commit is contained in:
parent
3051eb0e48
commit
e7440eff8f
2 changed files with 23 additions and 5 deletions
|
@ -469,15 +469,23 @@ void test_create_exe_imp(const WCHAR* name, int skip_rsrc_exports)
|
||||||
HANDLE file;
|
HANDLE file;
|
||||||
char *buf, *cur;
|
char *buf, *cur;
|
||||||
DWORD size = 0x800;
|
DWORD size = 0x800;
|
||||||
|
|
||||||
buf = malloc(size);
|
buf = malloc(size);
|
||||||
|
winetest_ok(buf != NULL, "malloc failed\n");
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
|
winetest_ok(file != INVALID_HANDLE_VALUE, "can't create file\n");
|
||||||
if(file == INVALID_HANDLE_VALUE)
|
if (file == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
free(buf);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
memset(buf, 0, size);
|
memset(buf, 0, size);
|
||||||
cur = buf;
|
|
||||||
cur = memcpy(buf, &dos_header, sizeof(dos_header));
|
cur = memcpy(buf, &dos_header, sizeof(dos_header));
|
||||||
cur += dos_header.e_lfanew;
|
cur += dos_header.e_lfanew;
|
||||||
|
|
||||||
|
|
|
@ -569,16 +569,26 @@ static BOOL create_file(LPCSTR dir, LPCSTR name, int filler, DWORD size)
|
||||||
{
|
{
|
||||||
char target[MAX_PATH], *tmp;
|
char target[MAX_PATH], *tmp;
|
||||||
HANDLE file;
|
HANDLE file;
|
||||||
PathCombineA(target, dir, name);
|
|
||||||
|
|
||||||
tmp = malloc(size);
|
tmp = malloc(size);
|
||||||
memset(tmp, filler, size);
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathCombineA(target, dir, name);
|
||||||
|
|
||||||
file = CreateFileA(target, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
file = CreateFileA(target, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
if(file == INVALID_HANDLE_VALUE)
|
if (file == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
free(tmp);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tmp, filler, size);
|
||||||
WriteFile(file, tmp, size, &size, NULL);
|
WriteFile(file, tmp, size, &size, NULL);
|
||||||
|
|
||||||
CloseHandle(file);
|
CloseHandle(file);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Reference in a new issue