title: GLib Hash Table Lookup Failure
body: <p>I'm trying to learn how to use the GHashTable container from glib, and I'm seeing some strange behavior in lookups. The problem boils down to the following:</p>
  
  <pre><code>#include &lt;glib.h&gt;
  #include &lt;stdio.h&gt;
  
  GHashTable *h;
  char val[]  = {'H', 'E', 'L', 'L', 'O',0};
  
  void f1()
  {
     int k;
     scanf("%d", &amp;k);
          g_hash_table_insert(h, &amp;k, val);
  }
  
  void f2()
  {
     int m;
     f1();
     scanf("%d", &amp;m);
     gpointer *p = g_hash_table_lookup(h, &amp;m);
     printf("%s\n", (const char*)p);
  }
  
  int main()
  {
     h = g_hash_table_new(g_int_hash, g_int_equal);
     f2();
     return 0;
  }
  </code></pre>
  
  <p>In function <code>f2</code>, the result of <code>g_hash_table_lookup</code> is 0x00. However, if I call <code>f1</code> from main before calling <code>f2</code> and skip calling <code>f1</code> from <code>f2</code>, the code works as expected and prints "HELLO".</p>
  
  <p>I think I'm missing something very basic here. How do I do hash table inserts and lookups correctly in glib?</p>