Skip to content

Commit c01e010

Browse files
committed
Reserve and commit memory in one step (fixes error found by Coverity, CID 989314).
1 parent 2b846b7 commit c01e010

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

MemoryModule.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,18 @@ HMEMORYMODULE MemoryLoadLibrary(const void *data)
323323
}
324324

325325
// reserve memory for image of library
326+
// XXX: is it correct to commit the complete memory region at once?
327+
// calling DllEntry raises an exception if we don't...
326328
code = (unsigned char *)VirtualAlloc((LPVOID)(old_header->OptionalHeader.ImageBase),
327329
old_header->OptionalHeader.SizeOfImage,
328-
MEM_RESERVE,
330+
MEM_RESERVE | MEM_COMMIT,
329331
PAGE_READWRITE);
330332

331333
if (code == NULL) {
332334
// try to allocate memory at arbitrary position
333335
code = (unsigned char *)VirtualAlloc(NULL,
334336
old_header->OptionalHeader.SizeOfImage,
335-
MEM_RESERVE,
337+
MEM_RESERVE | MEM_COMMIT,
336338
PAGE_READWRITE);
337339
if (code == NULL) {
338340
#if DEBUG_OUTPUT
@@ -348,13 +350,6 @@ HMEMORYMODULE MemoryLoadLibrary(const void *data)
348350
result->modules = NULL;
349351
result->initialized = 0;
350352

351-
// XXX: is it correct to commit the complete memory region at once?
352-
// calling DllEntry raises an exception if we don't...
353-
VirtualAlloc(code,
354-
old_header->OptionalHeader.SizeOfImage,
355-
MEM_COMMIT,
356-
PAGE_READWRITE);
357-
358353
// commit memory for headers
359354
headers = (unsigned char *)VirtualAlloc(code,
360355
old_header->OptionalHeader.SizeOfHeaders,

0 commit comments

Comments
 (0)