Replace se alloced memory in compare stat tap.

Also replaced comments mentioning se_alloc memory with wmem_file_scope, since it's more accurate.

It seems that many of the TShark stat taps may be leaking memory, because the hash tables created by the taps don't get a chance to be freed.  Somewhat academic since TShark exits shortly after displaying any stats, but a leak none the less.

Change-Id: I8ceecbd00d65b3442dc02d720b39c2e15aa0c8a6
Reviewed-on: https://code.wireshark.org/review/6557
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2015-01-11 19:48:54 -05:00
parent 7d43836b3a
commit e530c89940
9 changed files with 36 additions and 17 deletions

View File

@ -26,7 +26,7 @@
* However, take into account that when the packet dissection
* completes, these buffers will be automatically reclaimed/freed.
* If you need the buffer to remain for a longer scope than packet lifetime
* you must copy the content to an se_alloc() buffer.
* you must copy the content to an wmem_file_scope() buffer.
*/
#ifndef __RESOLV_H__

View File

@ -2188,7 +2188,7 @@ static void dcom_reinit( void) {
dcom_machines = NULL;
}
/* The data in dcom_interfaces is se_alloc'd so there's no need to free
/* The data in dcom_interfaces is wmem_file_scoped so there's no need to free
* the data pointers.
*/
if (dcom_interfaces != NULL) {

View File

@ -1540,7 +1540,7 @@ static void giop_init(void) {
/*
* Create objkey/repoid hash, use my "equal" and "hash" functions.
* Note: keys and values are se_alloc'd so they don't need to be freed.
* Note: keys and values are wmem_file_scoped so they don't need to be freed.
*
*/
@ -1557,7 +1557,7 @@ static void giop_init(void) {
/*
* Create complete_reply_hash, use my "equal" and "hash" functions.
* Note: keys and values are se_alloc'd so they don't need to be freed.
* Note: keys and values are wmem_file_scoped so they don't need to be freed.
*
*/
@ -1574,7 +1574,7 @@ static void giop_init(void) {
/*
* Free giop_complete_request_list (if necessary)
* Note: The data elements are se_alloc'd so only the
* Note: The data elements are wmem_file_scoped so only the
* actual list elements need to be freed.
*/

View File

@ -75,8 +75,8 @@ struct _rtp_info {
#if 0 /* these are only needed once the dissector include the crypto functions to decrypt and/or authenticate */
struct srtp_key_info
{
guint8 *master_key; /* pointer to an se_alloc'ed master key */
guint8 *master_salt; /* pointer to an se_alloc'ed salt for this master key - NULL if no salt */
guint8 *master_key; /* pointer to an wmem_file_scope'ed master key */
guint8 *master_salt; /* pointer to an wmem_file_scope'ed salt for this master key - NULL if no salt */
guint8 key_generation_rate; /* encoded as the power of 2, 0..24, or 255 (=zero rate) */
/* Either the MKI value is used (in which case from=to=0), or the <from,to> values are used (and MKI=0) */
guint32 from_roc; /* 32 MSBs of a 48 bit value - frame from which this key is valid (roll-over counter part) */
@ -94,7 +94,7 @@ struct srtp_info
guint mki_len; /* number of octets used for the MKI in the RTP payload */
guint auth_tag_len; /* number of octets used for the Auth Tag in the RTP payload */
#if 0 /* these are only needed once the dissector include the crypto functions to decrypt and/or authenticate */
struct srtp_key_info **master_keys; /* an array of pointers to master keys and their info, the array and each key struct being se_alloc'ed */
struct srtp_key_info **master_keys; /* an array of pointers to master keys and their info, the array and each key struct being wmem_file_scope'ed */
void *enc_alg_info, /* algorithm-dependent info struct - may be void for default alg with default params */
void *auth_alg_info /* algorithm-dependent info struct - void for default alg with default params */
#endif

View File

@ -540,7 +540,7 @@ extern guint
ssl_private_key_hash (gconstpointer v);
/* private key table entries have a scope 'larger' then packet capture,
* so we can't relay on se_alloc** function */
* so we can't rely on wmem_file_scope function */
extern void
ssl_private_key_free(gpointer id, gpointer key, gpointer dummy _U_);

View File

@ -24,7 +24,7 @@
* However, take into account that when the packet dissection
* completes, these buffers will be automatically reclaimed/freed.
* If you need the buffer to remain for a longer scope than packet lifetime
* you must copy the content to an se_alloc() buffer.
* you must copy the content to an wmem_file_scope() buffer.
*/
#ifndef __NEXT_TVB_H__

View File

@ -124,7 +124,7 @@ WS_DLL_PUBLIC void oids_cleanup(void);
* However, take into account that when the packet dissection
* completes, these buffers will be automatically reclaimed/freed.
* If you need the buffer to remain for a longer scope than packet lifetime
* you must copy the content to an se_alloc() buffer.
* you must copy the content to an wmem_file_scope() buffer.
*/
/*

View File

@ -135,8 +135,8 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
computed_cksum = in_cksum(&cksum_vec[0], 3);
/* collect all packet infos */
fInfo = (frame_info*)se_alloc(sizeof(frame_info));
fInfo->fp = (for_print*)se_alloc(sizeof(for_print));
fInfo = (frame_info*)g_malloc(sizeof(frame_info));
fInfo->fp = (for_print*)g_malloc(sizeof(for_print));
fInfo->fp->partner = NULL;
fInfo->fp->count = 1;
fInfo->fp->cksum = computed_cksum;
@ -153,6 +153,16 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
return 1;
}
static void
frame_info_free(gpointer data)
{
frame_info *fInfo = (frame_info *)data;
g_free(fInfo->fp);
g_free(fInfo);
}
/* Find equal packets, same IP-Id, count them and make time statistics */
static void
call_foreach_count_ip_id(gpointer key _U_, gpointer value, gpointer arg)
@ -549,7 +559,7 @@ comparestat_init(const char *opt_arg, void *userdata _U_)
}
/* create a Hash to count the packets with the same ip.id */
cs->packet_set = g_hash_table_new(NULL, NULL);
cs->packet_set = g_hash_table_new_full(NULL, NULL, NULL, frame_info_free);
error_string = register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw);
if (error_string) {

View File

@ -203,8 +203,8 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
}
/* collect all packet infos */
fInfo=(frame_info*)se_alloc(sizeof(frame_info));
fInfo->fg=(for_gui*)se_alloc(sizeof(for_gui));
fInfo=(frame_info*)g_malloc(sizeof(frame_info));
fInfo->fg=(for_gui*)g_malloc(sizeof(for_gui));
fInfo->fg->partner=NULL;
fInfo->fg->count=1;
fInfo->fg->cksum=computed_cksum;
@ -226,6 +226,15 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
}
}
static void
frame_info_free(gpointer data)
{
frame_info *fInfo = (frame_info *)data;
g_free(fInfo->fg);
g_free(fInfo);
}
/* Find equal packets, same IP-Id, count them and make time statistics */
static void
call_foreach_count_ip_id(gpointer key _U_, gpointer value, gpointer arg)
@ -778,7 +787,7 @@ gtk_comparestat_init(const char *opt_arg, void* userdata _U_)
gtk_box_pack_start(GTK_BOX(vbox), cs->scrolled_win, TRUE, TRUE, 0);
/* create a Hash to count the packets with the same ip.id */
cs->packet_set=g_hash_table_new(NULL, NULL);
cs->packet_set=g_hash_table_new_full(NULL, NULL, NULL, frame_info_free);
error_string=register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw);
if(error_string){