When failing, it should not tamper at all with the data it was supposed to
add to the cache.
++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 */