FabianHahn / fakeglib

A fake implementation of parts of the glib API in C++
MIT License
7 stars 0 forks source link

g_hash_table_add shouldn't be a macro #2

Open FabianHahn opened 4 years ago

FabianHahn commented 4 years ago

g_hash_table_add currently just wraps g_hash_table_replace in a macro. However, this is problematic when calling it with things like string keys that are managed by the hash table:

void addItemToSet(GHashTable *table, const char *key) {
    g_hash_table_add(table, strdup(key));
}

Because of the macro, this will end up calling strdup twice and leaking the memory for the second copy.