Glib segfault g_free hash table

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-11T19:04:10Z Indexed on 2010/03/11 19:09 UTC
Read the original article Hit count: 294

Filed under:
|

I'm not quite sure why if I try to free the data I get segfault. Any help will be appreciate it.

static GHashTable *hashtable;

static void add_inv(char *q)
{
    gpointer old_key, old_value;

    if(!g_hash_table_lookup_extended(hashtable, q, &old_key, &old_value)){
        g_hash_table_insert(hashtable, g_strdup(q), GINT_TO_POINTER(10));
    }else{
        (old_value)++;
        g_hash_table_insert(hashtable, g_strdup(q), old_value);
        g_hash_table_remove (hashtable, q); // segfault
        g_free(old_key);   // segfault
        g_free(old_value); // segfault
    }   
}
...
int main(int argc, char *argv[]){
  hashtable = g_hash_table_new(g_str_hash, g_str_equal);
  ...
  g_hash_table_destroy(hashtable);
}

© Stack Overflow or respective owner

Related posts about glib

Related posts about c