X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=mem.c;h=6ac80e61a28897ffb1d39160ada4658a5358bf04;hb=de18b56efecadc4b5d2473904828db9c08cd2162;hp=9bee71d14fe503e9278596f5f4a492db548c399a;hpb=0f4971d043c38bae1bfb95201622a1405110f899;p=onak.git diff --git a/mem.c b/mem.c index 9bee71d..6ac80e6 100644 --- a/mem.c +++ b/mem.c @@ -1,20 +1,29 @@ /* * mem.c - Routines to cleanup memory after use. * - * Jonathan McDowell + * Copyright 2002-2004,2007 Jonathan McDowell * - * Copyright 2002 Project Purple + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; version 2 of the License. * - * $Id: mem.c,v 1.5 2003/06/04 20:57:10 noodles Exp $ + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ -#include #include #include +#include #include "keystructs.h" #include "ll.h" #include "mem.h" +#include "stats.h" /** * packet_dup - duplicate an OpenPGP packet. @@ -28,7 +37,8 @@ struct openpgp_packet *packet_dup(struct openpgp_packet *packet) { struct openpgp_packet *newpacket = NULL; - assert(packet != NULL); + if (packet == NULL) + return NULL; newpacket = malloc(sizeof (struct openpgp_packet)); if (newpacket != NULL) { @@ -60,9 +70,6 @@ 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); - for (; packet_list != NULL; packet_list = packet_list->next) { ADD_PACKET_TO_LIST((*list_end), packet_dup(packet_list->packet)); @@ -82,8 +89,6 @@ void packet_list_add(struct openpgp_packet_list **list, * including the data part. */ void free_packet(struct openpgp_packet *packet) { - assert(packet != NULL); - if (packet->data != NULL) { free(packet->data); packet->data = NULL; @@ -101,8 +106,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) { @@ -124,8 +127,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) { @@ -149,17 +150,15 @@ 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) { free_packet(key->publickey); key->publickey = NULL; } - if (key->revocations != NULL) { - free_packet_list(key->revocations); - key->revocations = NULL; + if (key->sigs != NULL) { + free_packet_list(key->sigs); + key->sigs = NULL; } if (key->uids != NULL) { free_signedpacket_list(key->uids); @@ -173,26 +172,3 @@ 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); - } -}