From e8f6a8635ce7415030d52925651d721322f55e80 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Thu, 7 Aug 2014 21:32:48 +0200 Subject: [PATCH] added pcphash_cleanpub() to free local pubkey hashes, which are not attached to any context --- include/pcp/keyhash.h | 5 ++++- libpcp/keyhash.c | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/pcp/keyhash.h b/include/pcp/keyhash.h index 813db37..03a2aab 100644 --- a/include/pcp/keyhash.h +++ b/include/pcp/keyhash.h @@ -88,9 +88,12 @@ */ void pcphash_del(PCPCTX *ptx, void *key, int type); -/** Free memory used by key hashes. */ +/** Free memory used by key global ptx-attached hashes. */ void pcphash_clean(PCPCTX *ptx); +/** Free memory by local pubkey hash */ +void pcphash_cleanpub(pcp_pubkey_t *pub); + /** Check if a secret key with a given key-id exists in the hash. \param[in] PCP Context object. diff --git a/libpcp/keyhash.c b/libpcp/keyhash.c index a601677..512648a 100644 --- a/libpcp/keyhash.c +++ b/libpcp/keyhash.c @@ -64,6 +64,14 @@ void pcphash_clean(PCPCTX *ptx) { } } +void pcphash_cleanpub(pcp_pubkey_t *pub) { + pcp_pubkey_t *current_pub, *ptmp; + HASH_ITER(hh, pub, current_pub, ptmp) { + HASH_DEL(pub, (pcp_pubkey_t *)current_pub); + memset(current_pub, 0, sizeof(pcp_pubkey_t)); + free(current_pub); + } +} pcp_keysig_t *pcphash_keysigexists(PCPCTX *ptx, char *id) { pcp_keysig_t *keysig = NULL;