From e3330fd9229c9b1dee36075ed260f6ded08af3b1 Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Mon, 15 Jan 2007 05:16:13 +0000 Subject: 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 svn path=/trunk/; revision=20437 --- epan/emem.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'epan/emem.c') 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 */ } } -- cgit v1.2.1