aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-09-09 17:51:30 +0000
committerEvan Huus <eapache@gmail.com>2013-09-09 17:51:30 +0000
commit771668d630e5d01b79046238e4b8b40eb2537016 (patch)
treea79b5ce2574a80edc8e5a1dfb614566ff83c16d6 /epan/dissectors
parentf74bd06ecf546cce93ed29db3fb5d8849f5f5cdd (diff)
Register a wmem callback to free the glib hash tables used in SMB2 conversation
structs. Fixes the most egregious of the memory leaks (around 300KB) from https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9120 svn path=/trunk/; revision=51873
Diffstat (limited to 'epan/dissectors')
-rw-r--r--epan/dissectors/packet-smb2.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/epan/dissectors/packet-smb2.c b/epan/dissectors/packet-smb2.c
index e08f6ca3f1..0c77a237ec 100644
--- a/epan/dissectors/packet-smb2.c
+++ b/epan/dissectors/packet-smb2.c
@@ -36,6 +36,7 @@
#include <epan/conversation.h>
#include <epan/tap.h>
#include <epan/emem.h>
+#include <epan/wmem/wmem.h>
#include <epan/aftypes.h>
#include "packet-smb2.h"
@@ -614,6 +615,24 @@ smb2_sesid_info_hash(gconstpointer k)
return hash;
}
+/* Callback for destroying the glib hash tables associated with a conversation
+ * struct. */
+static gboolean
+smb2_conv_destroy(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_,
+ void *user_data)
+{
+ smb2_conv_info_t *conv = (smb2_conv_info_t *)user_data;
+
+ g_hash_table_destroy(conv->matched);
+ g_hash_table_destroy(conv->unmatched);
+ g_hash_table_destroy(conv->sesids);
+ g_hash_table_destroy(conv->files);
+
+ /* This conversation is gone, return FALSE to indicate we don't
+ * want to be called again for this conversation. */
+ return FALSE;
+}
+
static void smb2_key_derivation(const guint8 *KI _U_, guint32 KI_len _U_,
const guint8 *Label _U_, guint32 Label_len _U_,
const guint8 *Context _U_, guint32 Context_len _U_,
@@ -6799,7 +6818,7 @@ dissect_smb2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, gboolea
/* no smb2_into_t structure for this conversation yet,
* create it.
*/
- si->conv = se_new(smb2_conv_info_t);
+ si->conv = wmem_new(wmem_file_scope(), smb2_conv_info_t);
/* qqq this leaks memory for now since we never free
the hashtables */
si->conv->matched = g_hash_table_new(smb2_saved_info_hash_matched,
@@ -6810,6 +6829,12 @@ dissect_smb2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, gboolea
smb2_sesid_info_equal);
si->conv->files = g_hash_table_new(smb2_eo_files_hash,smb2_eo_files_equal);
+ /* Bit of a hack to avoid leaking the hash tables - register a
+ * callback to free them. Ideally wmem would implement a simple
+ * hash table so we wouldn't have to do this. */
+ wmem_register_callback(wmem_file_scope(), smb2_conv_destroy,
+ si->conv);
+
conversation_add_proto_data(conversation, proto_smb2, si->conv);
}