title: GLib Hash Table Loop Problem
body: <p>I am going to use <a href="http://en.wikipedia.org/wiki/GLib" rel="nofollow noreferrer">GLib</a>'s Hash table implementation in a C program and just for now 
  I am just experimenting with it. I wrote the following piece of code for testing:</p>
  
  <pre><code> #include &lt;glib.h&gt;
   #include &lt;stdlib.h&gt;
   #include &lt;stdint.h&gt;
   #include &lt;stdio.h&gt;
   #include &lt;string.h&gt;
  
   int main(){
   // Some codes and declerations here
   GHashTable *g_hash_table;
   uint32_t *a;
   a=(uint32_t *)malloc(sizeof(uint32_t));
   if(a==NULL){
      printf("Not Enough Mem For a\n");
      return 1;
   }
   *a=1123231;
  
   uint32_t* key;
   key=(uint32_t *)malloc(sizeof(uint32_t));
   if(key==NULL){
       printf("Not Enough Mem For key\n");
       return 1;
   }
   *key=122312312;
   int i;
   g_hash_table=g_hash_table_new(g_int_hash, g_int_equal);
   for(i=0;i&lt;TABLE_SIZE;i++){
       *key+=1;
       *a+=1;
       g_hash_table_insert(g_hash_table,(gpointer)key,(gpointer)a);
       uint32_t *x=(uint32_t *)g_hash_table_lookup(g_hash_table,key);
       printf("Counter:%d,  %u\n",i,*x);
   }
  
  GHashTableIter iter;
  g_hash_table_iter_init(&amp;iter,g_hash_table);
  int size=g_hash_table_size(g_hash_table);
  printf("First size: %d\n",size);
  uint32_t *val;
  uint32_t *key_;
  int counter=0;
  
  // My problem is in the following loop it 
  // always returns the same and the last key value pair
   while(g_hash_table_iter_next(&amp;iter,(gpointer*)(void*)&amp;key_,(gpointer*)(void*)&amp;val)){
       counter++;
       printf("%u %u\n",(uint32_t)*key_,(uint32_t)*val);
       printf("Counter: %d\n",counter);
   }
   //Some more code here        
      return 0;
  }
  </code></pre>
  
  <p>Somehow my test code iterates correctly but in the loop it always returns the last key and last value pairs and it is always the same. What is the problem here? The above code may not run with its as it is format. I just copied and pasted some parts to give a clear idea about what I am trying to do.</p>