export_pdu.c: Fix a memory leak

Allocate the exp_pdu_data using the wmem_packet_scope allocator so the
epan_dissect_run_with_taps will free it after calling all registered tap
listeners.

valgrind --tool=memcheck --leak-check=full ./run/tshark -r sctp.pcap -U "OSI layer 3" -w exported.pcap

32 bytes in 1 blocks are definitely lost in loss record 48 of 76
   at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
   by 0xB3FC3C5: g_malloc (gmem.c:99)
   by 0x68C2BE1: export_pdu_create_tags (exported_pdu.c:251)
   by 0x68C2D5E: export_pdu_create_common_tags (exported_pdu.c:231)
   by 0x70AA54E: create_exp_pdu_proto_name (packet-sctp.c:3240)
   by 0x70AA54E: export_sctp_data_chunk.part.23 (packet-sctp.c:3268)
   by 0x70AB76B: export_sctp_data_chunk (packet-sctp.c:3256)
   by 0x70AB76B: dissect_data_chunk (packet-sctp.c:3509)

Change-Id: I6e247ab2861bbb053f0958faf253913b28dbcbeb
Reviewed-on: https://code.wireshark.org/review/29126
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Vasil Velichkov 2018-08-13 21:48:06 +03:00 committed by Anders Broman
parent 68c9566419
commit 88dd7e734a
2 changed files with 2 additions and 3 deletions

View File

@ -248,7 +248,7 @@ export_pdu_create_tags(packet_info *pinfo, const char* proto_name, guint16 tag_t
DISSECTOR_ASSERT(proto_name != NULL);
DISSECTOR_ASSERT((tag_type == EXP_PDU_TAG_PROTO_NAME) || (tag_type == EXP_PDU_TAG_HEUR_PROTO_NAME) || (tag_type == EXP_PDU_TAG_DISSECTOR_TABLE_NAME));
exp_pdu_data = (exp_pdu_data_t *)g_malloc(sizeof(exp_pdu_data_t));
exp_pdu_data = (exp_pdu_data_t *)wmem_alloc(wmem_packet_scope(), sizeof(exp_pdu_data_t));
/* Start by computing size of protocol name as a tag */
proto_str_len = (int)strlen(proto_name);
@ -268,7 +268,7 @@ export_pdu_create_tags(packet_info *pinfo, const char* proto_name, guint16 tag_t
/* Add end of options length */
tag_buf_size+=4;
exp_pdu_data->tlv_buffer = (guint8 *)g_malloc0(tag_buf_size);
exp_pdu_data->tlv_buffer = (guint8 *)wmem_alloc0(wmem_packet_scope(), tag_buf_size);
exp_pdu_data->tlv_buffer_len = tag_buf_size;
buffer_data = exp_pdu_data->tlv_buffer;

View File

@ -41,7 +41,6 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
if(exp_pdu_data->tlv_buffer_len > 0){
memcpy(packet_buf, exp_pdu_data->tlv_buffer, exp_pdu_data->tlv_buffer_len);
g_free(exp_pdu_data->tlv_buffer);
}
if(exp_pdu_data->tvb_captured_length > 0){
tvb_memcpy(exp_pdu_data->pdu_tvb, packet_buf+exp_pdu_data->tlv_buffer_len, 0, exp_pdu_data->tvb_captured_length);