diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2007-01-15 05:16:13 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2007-01-15 05:16:13 +0000 |
commit | e3330fd9229c9b1dee36075ed260f6ded08af3b1 (patch) | |
tree | 65a493d1fa5798cb206fb7edb6ef6cdf72973b05 /epan | |
parent | e31d777279d28800e520549fd8ad4c7f2d4b089e (diff) | |
download | wireshark-e3330fd9229c9b1dee36075ed260f6ded08af3b1.tar.gz |
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
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-ethertype.c | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-frame.c | 3 | ||||
-rw-r--r-- | epan/emem.c | 14 | ||||
-rw-r--r-- | epan/exceptions.h | 6 | ||||
-rw-r--r-- | epan/packet.c | 6 |
5 files changed, 29 insertions, 3 deletions
diff --git a/epan/dissectors/packet-ethertype.c b/epan/dissectors/packet-ethertype.c index d06a167deb..b4ded722b6 100644 --- a/epan/dissectors/packet-ethertype.c +++ b/epan/dissectors/packet-ethertype.c @@ -216,6 +216,9 @@ ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype, else. */ RETHROW; } + CATCH(OutOfMemoryError) { + RETHROW; + } CATCH_ALL { /* Somebody threw an exception other than BoundsError, which means that a dissector was found, so we don't need to diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 65d50b3249..d3a695dcd8 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -313,6 +313,9 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) } #endif } + CATCH(OutOfMemoryError) { + RETHROW; + } CATCH_ALL { show_exception(tvb, pinfo, parent_tree, EXCEPT_CODE, GET_MESSAGE); } 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 */ } } diff --git a/epan/exceptions.h b/epan/exceptions.h index b087f01a7e..acf9b78a27 100644 --- a/epan/exceptions.h +++ b/epan/exceptions.h @@ -67,6 +67,12 @@ **/ #define ScsiBoundsError 5 +/** + Running out of memory. + A dissector tried to allocate memory but that failed. +**/ +#define OutOfMemoryError 6 + /* Usage: * diff --git a/epan/packet.c b/epan/packet.c index 50f3e34cee..8b039fbe9a 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -338,6 +338,9 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header, g_assert_not_reached(); } } + CATCH(OutOfMemoryError) { + RETHROW; + } ENDTRY; fd->flags.visited = 1; @@ -546,6 +549,9 @@ call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb, */ ret = tvb_length(tvb); } + CATCH(OutOfMemoryError) { + RETHROW; + } ENDTRY; col_set_writable(pinfo->cinfo, save_writable); |