6LoWPAN: use manually managed memory for the stateful address decompression preferences
authorPascal Quantin <pascal.quantin@gmail.com>
Mon, 1 Dec 2014 16:21:41 +0000 (17:21 +0100)
committerPascal Quantin <pascal.quantin@gmail.com>
Tue, 2 Dec 2014 09:43:46 +0000 (09:43 +0000)
Bug: 10747
Change-Id: I9d1b7ce2782f7cd133ab3ba02b0dd43afab3e145
Reviewed-on: https://code.wireshark.org/review/5560
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
epan/dissectors/packet-6lowpan.c

index c33437f8db9b6a40cc6154c250d99840799da650..28c5d1221d1cbaba9d9fc40e23c21cabdeadaab1 100644 (file)
@@ -626,11 +626,12 @@ lowpan_context_insert(guint8 cid, guint16 pan, guint8 plen, struct e_in6_addr *p
     /* Sanity! */
     if (plen > 128) return;
     if (!prefix) return;
+    if (!lowpan_context_table) return;
 
     /* Search the context table for an existing entry. */
     key.pan = pan;
     key.cid = cid;
-    if (g_hash_table_lookup_extended(lowpan_context_table, &key, &pkey, &pdata)) {
+    if (g_hash_table_lookup_extended(lowpan_context_table, &key, NULL, &pdata)) {
         /* Context already exists. */
         data = (lowpan_context_data *)pdata;
         if ( (data->plen == plen) && (memcmp(&data->prefix, prefix, (plen+7)/8) == 0) ) {
@@ -638,12 +639,10 @@ lowpan_context_insert(guint8 cid, guint16 pan, guint8 plen, struct e_in6_addr *p
             return;
         }
     }
-    else {
-        pkey = wmem_memdup(wmem_file_scope(), &key, sizeof(key));
-    }
+    pkey = wmem_memdup(NULL, &key, sizeof(key));
 
     /* Create a new context */
-    data = wmem_new(wmem_file_scope(), lowpan_context_data);
+    data = wmem_new(NULL, lowpan_context_data);
     data->frame = frame;
     data->plen = plen;
     memset(&data->prefix, 0, sizeof(struct e_in6_addr)); /* Ensure zero paddeding */
@@ -651,6 +650,23 @@ lowpan_context_insert(guint8 cid, guint16 pan, guint8 plen, struct e_in6_addr *p
     g_hash_table_insert(lowpan_context_table, pkey, data);
 } /* lowpan_context_insert */
 
+/*FUNCTION:------------------------------------------------------
+ *  NAME
+ *      lowpan_context_free
+ *  DESCRIPTION
+ *     Frees the allocated memory for the context hash table
+ *  PARAMETERS
+ *      data            ; Pointer to key or value
+ *  RETURNS
+ *      void            ;
+ *---------------------------------------------------------------
+ */
+void
+lowpan_context_free(gpointer data)
+{
+    wmem_free(NULL, data);
+} /* lowpan_context_free */
+
 /*FUNCTION:------------------------------------------------------
  *  NAME
  *      lowpan_addr16_to_ifcid
@@ -2823,7 +2839,7 @@ proto_init_6lowpan(void)
     /* Initialize the context table. */
     if (lowpan_context_table)
         g_hash_table_destroy(lowpan_context_table);
-    lowpan_context_table = g_hash_table_new(lowpan_context_hash, lowpan_context_equal);
+    lowpan_context_table = g_hash_table_new_full(lowpan_context_hash, lowpan_context_equal, lowpan_context_free, lowpan_context_free);
 
 
     /* Initialize the link-local context. */