X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/4b8483ae278577a3adc8d84da81d77019704466f..ed841dbf668ab9b92868064f0baada6c922322a8:/mem.c?ds=inline diff --git a/mem.c b/mem.c index 1b9627c..00507ab 100644 --- a/mem.c +++ b/mem.c @@ -6,12 +6,13 @@ * Copyright 2002 Project Purple */ -#include #include #include +#include #include "keystructs.h" #include "ll.h" +#include "log.h" #include "mem.h" /** @@ -26,7 +27,7 @@ struct openpgp_packet *packet_dup(struct openpgp_packet *packet) { struct openpgp_packet *newpacket = NULL; - assert(packet != NULL); + log_assert(packet != NULL); newpacket = malloc(sizeof (struct openpgp_packet)); if (newpacket != NULL) { @@ -58,8 +59,8 @@ void packet_list_add(struct openpgp_packet_list **list, struct openpgp_packet_list **list_end, struct openpgp_packet_list *packet_list) { - assert(list != NULL); - assert(list_end != NULL); + log_assert(list != NULL); + log_assert(list_end != NULL); for (; packet_list != NULL; packet_list = packet_list->next) { ADD_PACKET_TO_LIST((*list_end), @@ -80,7 +81,7 @@ void packet_list_add(struct openpgp_packet_list **list, * including the data part. */ void free_packet(struct openpgp_packet *packet) { - assert(packet != NULL); + log_assert(packet != NULL); if (packet->data != NULL) { free(packet->data); @@ -99,8 +100,6 @@ void free_packet(struct openpgp_packet *packet) { void free_packet_list(struct openpgp_packet_list *packet_list) { struct openpgp_packet_list *nextpacket = NULL; - assert(packet_list != NULL); - while (packet_list != NULL) { nextpacket = packet_list->next; if (packet_list->packet != NULL) { @@ -122,8 +121,6 @@ void free_signedpacket_list( struct openpgp_signedpacket_list *signedpacket_list) { struct openpgp_signedpacket_list *nextpacket = NULL; - assert(signedpacket_list != NULL); - while (signedpacket_list != NULL) { nextpacket = signedpacket_list->next; if (signedpacket_list->packet != NULL) { @@ -147,8 +144,6 @@ void free_signedpacket_list( void free_publickey(struct openpgp_publickey *key) { struct openpgp_publickey *nextkey = NULL; - assert(key != NULL); - while (key != NULL) { nextkey = key->next; if (key->publickey != NULL) { @@ -171,3 +166,26 @@ void free_publickey(struct openpgp_publickey *key) { key = nextkey; } } + +/** + * free_statskey - free an stats key structure. + * @key: The key to free. + * + * Takes a stats key and frees the memory used by it and the linked list + * of sigs under it. Doesn't recurse into the list as it's assumed all the + * objects referenced also exist in the hash. + */ +void free_statskey(struct stats_key *key) +{ + if (key != NULL) { + if (key->sigs != NULL) { + llfree(key->sigs, NULL); + key->sigs = NULL; + } + if (key->signs != NULL) { + llfree(key->signs, NULL); + key->signs = NULL; + } + free(key); + } +}