From b6cb757f4ee700ba033f52d6d0c1191b1bdf5f16 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 27 Dec 2010 16:38:30 +0100 Subject: [PATCH] Hashlist: add function to flush the contents of a hashlist. --- libcitadel/lib/hash.c | 32 +++++++++++++++++++++++++++----- libcitadel/lib/libcitadel.h | 1 + 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index 29f145894..26a20e53f 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -209,11 +209,11 @@ void HDeleteHash(void *vHash) } /** - * @brief destroy a hashlist and all of its members + * @brief flush the members of a hashlist * Crashing? do 'print *FreeMe->LookupTable[i]' * @param Hash Hash to destroy. Is NULL'ed so you are shure its done. */ -void DeleteHash(HashList **Hash) +void DeleteHashContent(HashList **Hash) { int i; HashList *FreeMe; @@ -237,12 +237,34 @@ void DeleteHash(HashList **Hash) free(FreeMe->LookupTable[i]); } } - /** now, free our arrays... */ - free(FreeMe->LookupTable); - free(FreeMe->Members); + FreeMe->nMembersUsed = 0; + FreeMe->tainted = 0; + FreeMe->nLookupTableItems = 0; + memset(FreeMe->Members, 0, sizeof(Payload*) * FreeMe->MemberSize); + memset(FreeMe->LookupTable, 0, sizeof(HashKey*) * FreeMe->MemberSize); + /** did s.b. want an array of our keys? free them. */ if (FreeMe->MyKeys != NULL) free(FreeMe->MyKeys); +} + +/** + * @brief destroy a hashlist and all of its members + * Crashing? do 'print *FreeMe->LookupTable[i]' + * @param Hash Hash to destroy. Is NULL'ed so you are shure its done. + */ +void DeleteHash(HashList **Hash) +{ + HashList *FreeMe; + + FreeMe = *Hash; + if (FreeMe == NULL) + return; + DeleteHashContent(Hash); + /** now, free our arrays... */ + free(FreeMe->LookupTable); + free(FreeMe->Members); + /** buye bye cruel world. */ free (FreeMe); *Hash = NULL; diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index f0c8ab735..d74b9f12d 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -454,6 +454,7 @@ long lFlathash(const char *str, long len); HashList *NewHash(int Uniq, HashFunc F); void DeleteHash(HashList **Hash); +void DeleteHashContent(HashList **Hash); void HDeleteHash(void *vHash); int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data); void Put(HashList *Hash, const char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt); -- 2.30.2