Give variable a better name.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4378 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c
index 9c925fb..7aef05d 100644
--- a/coregrind/m_hashtable.c
+++ b/coregrind/m_hashtable.c
@@ -108,6 +108,38 @@
    return curr;
 }
 
+/* Looks up a VgHashNode in the table.  Returns NULL if not found. */
+VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key )
+{
+   VgHashNode* curr = table->chains[ CHAIN_NO(key, table) ];
+
+   while (curr) {
+      if (key == curr->key) {
+         return curr;
+      }
+      curr = curr->next;
+   }
+   return NULL;
+}
+
+/* Removes a VgHashNode from the table.  Returns NULL if not found. */
+VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key )
+{
+   Int          chain         = CHAIN_NO(key, table);
+   VgHashNode*  curr          =   table->chains[chain];
+   VgHashNode** prev_next_ptr = &(table->chains[chain]);
+
+   while (curr) {
+      if (key == curr->key) {
+         *prev_next_ptr = curr->next;
+         return curr;
+      }
+      prev_next_ptr = &(curr->next);
+      curr = curr->next;
+   }
+   return NULL;
+}
+
 /* Allocates a suitably-sized array, copies all the malloc'd block
    shadows into it, then returns both the array and the size of it.  This is
    used by the memory-leak detector.
diff --git a/include/pub_tool_hashtable.h b/include/pub_tool_hashtable.h
index 6aa7efa..ec065f9 100644
--- a/include/pub_tool_hashtable.h
+++ b/include/pub_tool_hashtable.h
@@ -67,6 +67,12 @@
 extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
                                     /*OUT*/VgHashNode*** next_ptr );
 
+/* Looks up a VgHashNode in the table.  Returns NULL if not found. */
+extern VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key );
+
+/* Removes a VgHashNode from the table.  Returns NULL if not found. */
+extern VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key );
+
 /* Allocates an array of pointers to all the shadow chunks of malloc'd
    blocks.  Must be freed with VG_(free)(). */
 extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
diff --git a/memcheck/mac_malloc_wrappers.c b/memcheck/mac_malloc_wrappers.c
index fd5578f..5207f1d 100644
--- a/memcheck/mac_malloc_wrappers.c
+++ b/memcheck/mac_malloc_wrappers.c
@@ -282,9 +282,7 @@
 }
 
 static
-void die_and_free_mem ( ThreadId tid,
-                        MAC_Chunk* mc,
-                        MAC_Chunk** prev_chunks_next_ptr, SizeT rzB )
+void die_and_free_mem ( ThreadId tid, MAC_Chunk* mc, SizeT rzB )
 {
    /* Note: ban redzones again -- just in case user de-banned them
       with a client request... */
@@ -292,12 +290,6 @@
    MAC_(die_mem_heap)( mc->data, mc->size );
    MAC_(ban_mem_heap)( mc->data+mc->size, rzB );
 
-   /* Remove mc from the malloclist using prev_chunks_next_ptr to
-      avoid repeating the hash table lookup.  Can't remove until at least
-      after free and free_mismatch errors are done because they use
-      describe_addr() which looks for it in malloclist. */
-   *prev_chunks_next_ptr = mc->next;
-
    /* Put it out of harm's way for a while, if not from a client request */
    if (MAC_AllocCustom != mc->allockind) {
       /* Record where freed */
@@ -330,7 +322,13 @@
       MAC_(record_freemismatch_error) ( tid, p );
    }
 
-   die_and_free_mem ( tid, mc, prev_chunks_next_ptr, rzB );
+   /* Remove mc from the malloclist using prev_chunks_next_ptr to
+      avoid repeating the hash table lookup.  Can't remove until at least
+      after free_mismatch errors are done because they use
+      describe_addr() which looks for it in malloclist. */
+   *prev_chunks_next_ptr = mc->next;
+   die_and_free_mem ( tid, mc, rzB );
+
    VGP_POPCC(VgpCliMalloc);
 }
 
@@ -354,8 +352,8 @@
 
 void* MAC_(realloc) ( ThreadId tid, void* p, SizeT new_size )
 {
-   MAC_Chunk  *mc;
-   MAC_Chunk **prev_chunks_next_ptr;
+   MAC_Chunk*  mc;
+   MAC_Chunk** prev_chunks_next_ptr;
 
    VGP_PUSHCC(VgpCliMalloc);
 
@@ -416,7 +414,12 @@
       VG_(memcpy)((void*)p_new, p, mc->size);
 
       /* Free old memory */
-      die_and_free_mem ( tid, mc, prev_chunks_next_ptr, MAC_MALLOC_REDZONE_SZB );
+      /* Remove mc from the malloclist using prev_chunks_next_ptr to
+         avoid repeating the hash table lookup.  Can't remove until at least
+         after free_mismatch errors are done because they use
+         describe_addr() which looks for it in malloclist. */
+      *prev_chunks_next_ptr = mc->next;
+      die_and_free_mem ( tid, mc, MAC_MALLOC_REDZONE_SZB );
 
       /* this has to be after die_and_free_mem, otherwise the
          former succeeds in shorting out the new block, not the
@@ -492,10 +495,8 @@
 void MAC_(mempool_alloc)(ThreadId tid, Addr pool, Addr addr, SizeT size)
 {
    MAC_Mempool*  mp;
-   MAC_Mempool** prev_next;
 
-   mp = (MAC_Mempool*)VG_(HT_get_node) ( MAC_(mempool_list), (UWord)pool,
-                                        (void*)&prev_next );
+   mp = (MAC_Mempool*)VG_(HT_lookup) ( MAC_(mempool_list), (UWord)pool );
 
    if (mp == NULL) {
       MAC_(record_illegal_mempool_error) ( tid, pool );
@@ -509,28 +510,22 @@
 void MAC_(mempool_free)(Addr pool, Addr addr)
 {
    MAC_Mempool*  mp;
-   MAC_Mempool** prev_pool;
    MAC_Chunk*    mc;
-   MAC_Chunk**   prev_chunk;
    ThreadId      tid = VG_(get_running_tid)();
 
-   mp = (MAC_Mempool*)VG_(HT_get_node)(MAC_(mempool_list), (UWord)pool,
-                                       (void*)&prev_pool);
-
+   mp = (MAC_Mempool*)VG_(HT_lookup)(MAC_(mempool_list), (UWord)pool);
    if (mp == NULL) {
       MAC_(record_illegal_mempool_error)(tid, pool);
       return;
    }
 
-   mc = (MAC_Chunk*)VG_(HT_get_node)(mp->chunks, (UWord)addr,
-                                     (void*)&prev_chunk);
-
+   mc = (MAC_Chunk*)VG_(HT_remove)(mp->chunks, (UWord)addr);
    if (mc == NULL) {
       MAC_(record_free_error)(tid, (Addr)addr);
       return;
    }
 
-   die_and_free_mem ( tid, mc, prev_chunk, mp->rzB );
+   die_and_free_mem ( tid, mc, mp->rzB );
 }
 
 /*------------------------------------------------------------*/
diff --git a/memcheck/mac_shared.c b/memcheck/mac_shared.c
index d844861..26f66bd 100644
--- a/memcheck/mac_shared.c
+++ b/memcheck/mac_shared.c
@@ -437,7 +437,7 @@
    putting the result in ai. */
 static void describe_addr ( Addr a, AddrInfo* ai )
 {
-   MAC_Chunk* sc;
+   MAC_Chunk* mc;
    ThreadId   tid;
 
    /* Perhaps it's a user-def'd block ?  (only check if requested, though) */
@@ -453,21 +453,21 @@
       return;
    }
    /* Search for a recently freed block which might bracket it. */
-   sc = MAC_(first_matching_freed_MAC_Chunk)(addr_is_in_MAC_Chunk, &a);
-   if (NULL != sc) {
+   mc = MAC_(first_matching_freed_MAC_Chunk)(addr_is_in_MAC_Chunk, &a);
+   if (NULL != mc) {
       ai->akind      = Freed;
-      ai->blksize    = sc->size;
-      ai->rwoffset   = (Int)a - (Int)sc->data;
-      ai->lastchange = sc->where;
+      ai->blksize    = mc->size;
+      ai->rwoffset   = (Int)a - (Int)mc->data;
+      ai->lastchange = mc->where;
       return;
    }
    /* Search for a currently malloc'd block which might bracket it. */
-   sc = (MAC_Chunk*)VG_(HT_first_match)(MAC_(malloc_list), addr_is_in_HashNode, &a);
-   if (NULL != sc) {
+   mc = (MAC_Chunk*)VG_(HT_first_match)(MAC_(malloc_list), addr_is_in_HashNode, &a);
+   if (NULL != mc) {
       ai->akind      = Mallocd;
-      ai->blksize    = sc->size;
-      ai->rwoffset   = (Int)(a) - (Int)sc->data;
-      ai->lastchange = sc->where;
+      ai->blksize    = mc->size;
+      ai->rwoffset   = (Int)(a) - (Int)mc->data;
+      ai->lastchange = mc->where;
       return;
    }
    /* Clueless ... */