diff options
author | ulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-01-15 05:16:13 +0000 |
---|---|---|
committer | ulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-01-15 05:16:13 +0000 |
commit | 7a691a2473a80490cb5ceaf0bace0986b1bd8842 (patch) | |
tree | 65a493d1fa5798cb206fb7edb6ef6cdf72973b05 /epan/emem.c | |
parent | be64b743e8bd34cc7e24a4fb594e91d0472efa0c (diff) |
instead of simply doing an assert when running out of memory in emem, throw a new OutOfMemoryError Exception, so file.c can show at least a better explanation to the user before Wireshark terminates
XXX - to prevent a busy wait, I need a portable way to wait for a short time period, like Sleep() for Windows
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@20437 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/emem.c')
-rw-r--r-- | epan/emem.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/epan/emem.c b/epan/emem.c index 88945a8387..f4945d8f16 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -288,7 +288,9 @@ emem_create_chunk(emem_chunk_t **free_list) { /* XXX - is MEM_COMMIT|MEM_RESERVE correct? */ npc->buf = VirtualAlloc(NULL, EMEM_PACKET_CHUNK_SIZE, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); - g_assert(npc->buf != NULL); + if(npc->buf == NULL) { + THROW(OutOfMemoryError); + } buf_end = npc->buf + EMEM_PACKET_CHUNK_SIZE; /* Align our guard pages on page-sized boundaries */ @@ -308,7 +310,10 @@ emem_create_chunk(emem_chunk_t **free_list) { #elif defined(USE_GUARD_PAGES) npc->buf = mmap(NULL, EMEM_PACKET_CHUNK_SIZE, PROT_READ|PROT_WRITE, ANON_PAGE_MODE, ANON_FD, 0); - g_assert(npc->buf != MAP_FAILED); + if(npc->buf == MAP_FAILED) { + /* XXX - what do we have to cleanup here? */ + THROW(OutOfMemoryError); + } buf_end = npc->buf + EMEM_PACKET_CHUNK_SIZE; /* Align our guard pages on page-sized boundaries */ @@ -325,11 +330,14 @@ emem_create_chunk(emem_chunk_t **free_list) { npc->free_offset = npc->free_offset_init; #else /* Is there a draft in here? */ + npc->buf = malloc(EMEM_PACKET_CHUNK_SIZE); + if(npc->buf == NULL) { + THROW(OutOfMemoryError); + } npc->amount_free_init = EMEM_PACKET_CHUNK_SIZE; npc->amount_free = npc->amount_free_init; npc->free_offset_init = 0; npc->free_offset = npc->free_offset_init; - npc->buf = g_malloc(EMEM_PACKET_CHUNK_SIZE); #endif /* USE_GUARD_PAGES */ } } |