udvm: free the buffer *before* throwing the exception

Freeing it after the exception doesn't do much, for obvious reasons. Also move
the allocation a bit later, and add modelines.

This fixes one major memory leak, although on inspection this code still isn't
safe since there are exception-throwing functions called all over the place with
glib memory active. Outside the scope of this fix though.

Bug: 10265
Change-Id: I1fe272e92b92cac6b99abb84866b8ae9b582e24c
Reviewed-on: https://code.wireshark.org/review/2931
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Evan Huus 2014-07-08 00:04:21 -04:00 committed by Anders Broman
parent 8fbc0db7d2
commit 9d5bf53346
1 changed files with 16 additions and 3 deletions

View File

@ -319,8 +319,6 @@ decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet
offset++;
}
/* Largest allowed size for a message is UDVM_MEMORY_SIZE = 65536 */
out_buff = (guint8 *)g_malloc(UDVM_MEMORY_SIZE);
/* Start executing code */
current_address = udvm_start_ip;
input_address = 0;
@ -328,6 +326,9 @@ decompress_sigcomp_message(tvbuff_t *bytecode_tvb, tvbuff_t *message_tvb, packet
proto_tree_add_text(udvm_tree, bytecode_tvb, offset, 1,"UDVM EXECUTION STARTED at Address: %u Message size %u",
current_address, msg_end);
/* Largest allowed size for a message is UDVM_MEMORY_SIZE = 65536 */
out_buff = (guint8 *)g_malloc(UDVM_MEMORY_SIZE);
execute_next_instruction:
if ( used_udvm_cycles > maximum_UDVM_cycles ){
@ -2741,8 +2742,8 @@ decompression_failure:
proto_tree_add_text(udvm_tree, bytecode_tvb, 0, -1,"DECOMPRESSION FAILURE: %s",
val_to_str(result_code, result_code_vals,"Unknown (%u)"));
THROW(ReportedBoundsError);
g_free(out_buff);
THROW(ReportedBoundsError);
return NULL;
}
@ -3210,3 +3211,15 @@ decomp_dispatch_get_bits(
/* end udvm */
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/