]> granicus.if.org Git - curl/commitdiff
Curl_hash_add() was modified to clear up better in case of internal failure.
authorDaniel Stenberg <daniel@haxx.se>
Mon, 10 May 2004 09:17:50 +0000 (09:17 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 10 May 2004 09:17:50 +0000 (09:17 +0000)
When failing, it should not tamper at all with the data it was supposed to
add to the cache.

lib/hash.c

index fcc13ed28f669b412c6c359995ec20a5879964cf..51634e037527650b78597c38735f4447fc903a54 100644 (file)
@@ -169,8 +169,14 @@ Curl_hash_add(curl_hash *h, char *key, size_t key_len, void *p)
       ++h->size;
       return p; /* return the new entry */
     }
-    /* couldn't insert it, destroy the 'he' element again */
-    hash_element_dtor(h, he);
+    /*
+     * Couldn't insert it, destroy the 'he' element and the key again. We
+     * don't call hash_element_dtor() since that would also call the
+     * "destructor" for the actual data 'p'. When we fail, we shall not touch
+     * that data.
+     */
+    free(he->key);
+    free(he);
   }
 
   return NULL; /* failure */