aboutsummaryrefslogtreecommitdiffstats
path: root/epan/reassemble.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2011-05-13 05:19:23 +0000
committerAnders Broman <anders.broman@ericsson.com>2011-05-13 05:19:23 +0000
commit464486e1c5fe92475947174ad44e1d846c4c3926 (patch)
treed076827a1a41fba248d1183613ee872c4d7dc2fa /epan/reassemble.c
parent108e75ab4adb6a60e7ae04e6adaf2e651e5df5a2 (diff)
We should get rid of g_mem_chunk_alloc() as it leaks memory
http://www.wireshark.org/lists/wireshark-dev/200910/msg00074.html g_slice allocing the keys should make it possible to walk the fragment table and free the fragments once they are g_slice_alloced. It remains fo figure out how to do that. svn path=/trunk/; revision=37112
Diffstat (limited to 'epan/reassemble.c')
-rw-r--r--epan/reassemble.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/epan/reassemble.c b/epan/reassemble.c
index 574a0c2cd0..4a80d04fbb 100644
--- a/epan/reassemble.c
+++ b/epan/reassemble.c
@@ -281,15 +281,18 @@ static fragment_data *new_head(const guint32 flags)
/*
* For a reassembled-packet hash table entry, free the fragment data
* to which the value refers.
- * (The actual value structures get freed by "reassemble_cleanup()".)
+ * (Pre glib 2.10:The actual value structures get freed by "reassemble_cleanup()".)
+ * http://www.wireshark.org/lists/wireshark-dev/200910/msg00074.html
*/
static gboolean
-free_all_reassembled_fragments(gpointer key_arg _U_, gpointer value,
+free_all_reassembled_fragments(gpointer key_arg, gpointer value,
gpointer user_data _U_)
{
- fragment_data *fd_head;
+ fragment_data *fd_head, *tmp_fd;
+ reassembled_key *key = (reassembled_key *)key_arg;
- for (fd_head = value; fd_head != NULL; fd_head = fd_head->next) {
+ for (fd_head = value; fd_head != NULL; fd_head = tmp_fd) {
+ tmp_fd=fd_head->next;
if(fd_head->data && !(fd_head->flags&FD_NOT_MALLOCED)) {
g_free(fd_head->data);
@@ -302,6 +305,11 @@ free_all_reassembled_fragments(gpointer key_arg _U_, gpointer value,
*/
fd_head->data = NULL;
}
+#if GLIB_CHECK_VERSION(2,10,0)
+ if(key->frame == fd_head->reassembled_in){
+ g_slice_free(fragment_data, fd_head);
+ }
+#endif
}
return TRUE;
@@ -340,6 +348,17 @@ dcerpc_fragment_free_key(void *ptr)
}
}
#endif
+
+#if GLIB_CHECK_VERSION(2,10,0)
+static void
+reassembled_key_free(void *ptr)
+{
+ reassembled_key *key = (reassembled_key *)ptr;
+
+ g_slice_free(reassembled_key, key);
+}
+#endif
+
/*
* Initialize a fragment table.
*/
@@ -425,8 +444,13 @@ reassembled_table_init(GHashTable **reassembled_table)
free_all_reassembled_fragments, NULL);
} else {
/* The fragment table does not exist. Create it */
+#if GLIB_CHECK_VERSION(2,10,0)
+ *reassembled_table = g_hash_table_new_full(reassembled_hash,
+ reassembled_equal, reassembled_key_free, NULL);
+#else
*reassembled_table = g_hash_table_new(reassembled_hash,
reassembled_equal);
+#endif
}
}
@@ -719,7 +743,11 @@ fragment_reassembled(fragment_data *fd_head, const packet_info *pinfo,
* This was not fragmented, so there's no fragment
* table; just hash it using the current frame number.
*/
+#if GLIB_CHECK_VERSION(2,10,0)
+ new_key = g_slice_new(reassembled_key);
+#else
new_key = se_alloc(sizeof(reassembled_key));
+#endif
new_key->frame = pinfo->fd->num;
new_key->id = id;
g_hash_table_insert(reassembled_table, new_key, fd_head);
@@ -728,7 +756,11 @@ fragment_reassembled(fragment_data *fd_head, const packet_info *pinfo,
* Hash it with the frame numbers for all the frames.
*/
for (fd = fd_head->next; fd != NULL; fd = fd->next){
+#if GLIB_CHECK_VERSION(2,10,0)
+ new_key = g_slice_new(reassembled_key);
+#else
new_key = se_alloc(sizeof(reassembled_key));
+#endif
new_key->frame = fd->frame;
new_key->id = id;
g_hash_table_insert(reassembled_table, new_key,
@@ -1936,7 +1968,11 @@ fragment_end_seq_next(const packet_info *pinfo, const guint32 id, GHashTable *fr
*/
fragment_reassembled(fd_head, pinfo, reassembled_table, id);
if (fd_head->next != NULL) {
+#if GLIB_CHECK_VERSION(2,10,0)
+ new_key = g_slice_new(reassembled_key);
+#else
new_key = se_alloc(sizeof(reassembled_key));
+#endif
new_key->frame = pinfo->fd->num;
new_key->id = id;
g_hash_table_insert(reassembled_table, new_key, fd_head);