it's not really a leak, unless you forget to free the data (which is pretty much a tautology :-)).
you're probably thinking that all hash tables should use allocated strings and g_str_hash
as the hashing function.
GHashTable can use various types of keys. not ever key needs to be freed — for instance, if you pass NULL
to the hash function (or g_direct_hash
, which is exactly the same thing) then you use memory addresses as keys, so you don't have anything to free — i.e. you're not leaking memory.
there's also the case of having the key stored inside the value data, in case you have complex data structures stored inside the GHashTable
, e.g.:
typedef struct { char *foo; int bar; double baz; } Value;
GHashTable *table;
Value *value;
table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_value);
// fill up the Value data structure
value = value_init (value_alloc (), "foo", 42, M_PI / 4.0);
g_hash_table_insert (table, value->foo, value);
it would be pointless (and possibly a performance or memory usage issue) to copy the key out of the data structure for every insertion and removal.