When adding an entry to a dissector string table, take a copy of the pattern
authorEvan Huus <eapache@gmail.com>
Wed, 30 Oct 2013 01:42:11 +0000 (01:42 -0000)
committerEvan Huus <eapache@gmail.com>
Wed, 30 Oct 2013 01:42:11 +0000 (01:42 -0000)
string (and pass g_free to g_hash_table_new_full to free it).

This means callers don't have to worry about the scope of the memory they pass
in, and fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9296

svn path=/trunk/; revision=52977

epan/packet.c

index ade14b4403be89139e7920d51771976593b712d9..a30fdfdae5b8dd46020d6a413d77a7e83e95c002 100644 (file)
@@ -1152,7 +1152,7 @@ dissector_add_string(const char *name, const gchar *pattern,
        dtbl_entry->initial = dtbl_entry->current;
 
        /* do the table insertion */
-       g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
+       g_hash_table_insert( sub_dissectors->hash_table, (gpointer)g_strdup(pattern),
                             (gpointer)dtbl_entry);
 
        /*
@@ -1228,7 +1228,7 @@ dissector_change_string(const char *name, const gchar *pattern,
        dtbl_entry->current = handle;
 
        /* do the table insertion */
-       g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
+       g_hash_table_insert( sub_dissectors->hash_table, (gpointer)g_strdup(pattern),
                             (gpointer)dtbl_entry);
 }
 
@@ -1671,7 +1671,7 @@ register_dissector_table(const char *name, const char *ui_name, const ftenum_t t
        case FT_STRINGZ:
                sub_dissectors->hash_table = g_hash_table_new_full( g_str_hash,
                                                               g_str_equal,
-                                                              NULL,
+                                                              &g_free,
                                                               &g_free );
                break;