diff options
author | Anders Broman <anders.broman@ericsson.com> | 2010-01-20 20:26:01 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2010-01-20 20:26:01 +0000 |
commit | db64e65ec254b0550cb4c4cef2c058265f4ecc2e (patch) | |
tree | e6dcfccde3d76b4d27897a2a1e547babe4e73ab8 /epan/emem.c | |
parent | b5edad51e357ae993cde85b72361562220dba045 (diff) |
From Jakub Zawadzki:
mmap() actually when fail returns MAP_FAILED (-1) not NULL
Part of Bug:
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4140
svn path=/trunk/; revision=31593
Diffstat (limited to 'epan/emem.c')
-rw-r--r-- | epan/emem.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/epan/emem.c b/epan/emem.c index 56c5ccd992..97ceada4c6 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -618,19 +618,25 @@ emem_create_chunk() { npc->buf = VirtualAlloc(NULL, EMEM_PACKET_CHUNK_SIZE, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); + if (npc->buf == NULL) { + g_free(npc); + THROW(OutOfMemoryError); + } + #elif defined(USE_GUARD_PAGES) npc->buf = mmap(NULL, EMEM_PACKET_CHUNK_SIZE, PROT_READ|PROT_WRITE, ANON_PAGE_MODE, ANON_FD, 0); -#else /* Is there a draft in here? */ - npc->buf = g_malloc(EMEM_PACKET_CHUNK_SIZE); -#endif - - if(npc->buf == NULL) { + if (npc->buf == MAP_FAILED) { g_free(npc); THROW(OutOfMemoryError); } +#else /* Is there a draft in here? */ + npc->buf = g_malloc(EMEM_PACKET_CHUNK_SIZE); + /* g_malloc() can't fail */ +#endif + #ifdef SHOW_EMEM_STATS total_no_chunks++; #endif |