keys = NULL;
}
cleanupdb();
+ cleanupconfig();
} else {
puts("No OpenPGP packets found in input.");
}
dofindpath(from, to, true);
destroyhash();
cleanupdb();
+ cleanupconfig();
puts("<HR>");
- puts("Produced by gpgwww " VERSION ", part of onak. <A HREF=\"mailto:noodles-onak@earth.li\">Jonathan McDowell</A>");
+ puts("Produced by gpgwww " VERSION ", part of onak. "
+ "<A HREF=\"mailto:noodles-onak@earth.li\">"
+ "Jonathan McDowell</A>");
end_html();
+ cleanupcgi(cgiparams);
+ cgiparams = NULL;
+
return EXIT_SUCCESS;
}
#include "keydb.h"
#include "keyid.h"
#include "ll.h"
+#include "mem.h"
#include "stats.h"
/**
* TODO: The problem is the object has pointers that
* need freed too.
*/
- llfree(curll, free);
+ llfree(curll, free_statskey);
hashtable[i] = NULL;
}
elements = 0;
{
struct stats_key *key = NULL;
+ if (keyid == 0) {
+ return NULL;
+ }
+
key = findinhash(keyid);
if (key == NULL) {
key = malloc(sizeof(*key));
fetchbuf.size = data.size;
read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets);
parse_keys(packets, publickey);
+ free_packet_list(packets);
+ packets = NULL;
}
return (!ret);
read_openpgp_stream(buffer_fetchchar, &fetchbuf,
&packets);
parse_keys(packets, publickey);
+ free_packet_list(packets);
+ packets = NULL;
numkeys++;
} else if (ret != DB_NOTFOUND) {
dbconn->err(dbconn, ret, "Problem retrieving key");
llfind(keylist, data.data,
worddb_cmp) != NULL) {
newkeylist = lladd(newkeylist, data.data);
+ data.data = NULL;
} else {
free(data.data);
data.data = NULL;
llfree(keylist, free);
keylist = newkeylist;
newkeylist = NULL;
+ if (data.data != NULL) {
+ free(data.data);
+ data.data = NULL;
+ }
}
+ llfree(wordlist, NULL);
+ wordlist = NULL;
for (newkeylist = keylist; newkeylist != NULL;
newkeylist = newkeylist->next) {
dbconn->err(dbconn, ret, "Problem storing key");
}
+ free(storebuf.buffer);
+ storebuf.buffer = NULL;
+ storebuf.size = 0;
+ storebuf.offset = 0;
+
+ free_packet_list(packets);
+ packets = NULL;
+
/*
* Walk through our uids storing the words into the db with the keyid.
*/
if (fd > -1) {
read_openpgp_stream(file_fetchchar, &fd, &packets);
parse_keys(packets, publickey);
+ free_packet_list(packets);
+ packets = NULL;
close(fd);
}
write_openpgp_stream(file_putchar, &fd, packets);
close(fd);
+ free_packet_list(packets);
+ packets = NULL;
}
return (fd > -1);
* in and then parse_keys() to parse the packets into a publickey
* structure.
*/
-int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, bool intrans)
+int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
+ bool intrans)
{
struct openpgp_packet_list *packets = NULL;
PGresult *result = NULL;
&packets);
parse_keys(packets, publickey);
lo_close(dbconn, fd);
+ free_packet_list(packets);
+ packets = NULL;
}
}
} else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
&packets);
parse_keys(packets, publickey);
lo_close(dbconn, fd);
+ free_packet_list(packets);
+ packets = NULL;
}
}
} else if (PQresultStatus(result) != PGRES_TUPLES_OK) {
write_openpgp_stream(keydb_putchar, &fd, packets);
lo_close(dbconn, fd);
}
+ free_packet_list(packets);
+ packets = NULL;
snprintf(statement, 1023,
"INSERT INTO onak_keys (keyid, keydata) VALUES "
puts("Unknown operation!");
}
cleanupdb();
+ cleanupconfig();
}
puts("<hr>");
puts("Produced by onak " VERSION " by Jonathan McDowell");
findmaxpath(30);
destroyhash();
cleanupdb();
+ cleanupconfig();
return EXIT_SUCCESS;
}
#include "keystructs.h"
#include "ll.h"
#include "mem.h"
+#include "stats.h"
/**
* packet_dup - duplicate an OpenPGP packet.
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;
+ }
+ free(key);
+ }
+}
#define __MEM_H_
#include "keystructs.h"
+#include "stats.h"
/**
* packet_dup - duplicate an OpenPGP packet.
*/
void free_publickey(struct openpgp_publickey *key);
+/**
+ * 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);
+
#endif /* __MEM_H_ */
/*
* Options for directory backends.
*/
- "/home/noodles/onak-db", /* db_dir */
+ NULL, /* db_dir */
/*
* Options for the Postgres backend.
*/
NULL, /* pg_dbhost */
- "noodles", /* pg_dbname */
+ NULL, /* pg_dbname */
NULL, /* pg_dbuser */
NULL, /* pg_dbpass */
};
fprintf(stderr, "Couldn't open config file; using defaults.\n");
}
}
+
+void cleanupconfig(void) {
+ if (config.thissite != NULL) {
+ free(config.thissite);
+ config.thissite = NULL;
+ }
+ if (config.adminemail != NULL) {
+ free(config.adminemail);
+ config.adminemail = NULL;
+ }
+ if (config.mta != NULL) {
+ free(config.mta);
+ config.mta = NULL;
+ }
+ if (config.db_dir != NULL) {
+ free(config.db_dir);
+ config.db_dir = NULL;
+ }
+ if (config.pg_dbhost != NULL) {
+ free(config.pg_dbhost);
+ config.pg_dbhost = NULL;
+ }
+ if (config.pg_dbname != NULL) {
+ free(config.pg_dbname);
+ config.pg_dbname = NULL;
+ }
+ if (config.pg_dbuser != NULL) {
+ free(config.pg_dbuser);
+ config.pg_dbuser = NULL;
+ }
+ if (config.pg_dbpass != NULL) {
+ free(config.pg_dbpass);
+ config.pg_dbpass = NULL;
+ }
+ if (config.syncsites != NULL) {
+ llfree(config.syncsites, free);
+ config.syncsites = NULL;
+ }
+}
*/
void readconfig(void);
+/*
+ * cleanupconfig - clean up the config when we're shutting down.
+ */
+void cleanupconfig(void);
+
#endif /* __ONAK_CONF_H_ */
usage();
}
+ cleanupconfig();
+
return rc;
}
unsigned long findpath(struct stats_key *have, struct stats_key *want)
{
struct ll *keys = NULL;
+ struct ll *oldkeys = NULL;
struct ll *sigs = NULL;
struct ll *nextkeys = NULL;
long curdegree = 0;
curdegree = 1;
keys = lladd(NULL, want);
+ oldkeys = keys;
while (keys != NULL && have->colour == 0) {
sigs = hash_getkeysigs(((struct stats_key *)
keys = keys->next;
if (keys == NULL) {
keys = nextkeys;
+ llfree(oldkeys, NULL);
+ oldkeys = keys;
nextkeys = NULL;
curdegree++;
}
}
+ if (oldkeys != NULL) {
+ llfree(oldkeys, NULL);
+ oldkeys = NULL;
+ }
+ if (nextkeys != NULL) {
+ llfree(nextkeys, NULL);
+ nextkeys = NULL;
+ }
return count;
}
void dofindpath(uint64_t have, uint64_t want, bool html)
{
struct stats_key *keyinfoa, *keyinfob, *curkey;
+ uint64_t fullhave, fullwant;
int rec;
char *uid;
- have = getfullkeyid(have);
- want = getfullkeyid(want);
+ fullhave = getfullkeyid(have);
+ fullwant = getfullkeyid(want);
/*
* Make sure the keys we have and want are in the cache.
*/
- hash_getkeysigs(have);
- hash_getkeysigs(want);
+ hash_getkeysigs(fullhave);
+ hash_getkeysigs(fullwant);
- if ((keyinfoa = findinhash(have)) == NULL) {
+ if ((keyinfoa = findinhash(fullhave)) == NULL) {
printf("Couldn't find key 0x%llX.\n", have);
return;
}
- if ((keyinfob = findinhash(want)) == NULL) {
+ if ((keyinfob = findinhash(fullwant)) == NULL) {
printf("Couldn't find key 0x%llX.\n", want);
return;
}
" signs");
} else if (html && uid != NULL) {
printf("<a href=\"lookup?op=get&search=%llX\">"
- "0x%08llX</a> (<a href=\"lookup?op=vindex"
+ "0x%08llX</a>"
+ " (<a href=\"lookup?op=vindex"
"&search=0x%llX\">%s</a>)%s<BR>\n",
curkey->keyid & 0xFFFFFFFF,
curkey->keyid & 0xFFFFFFFF,
curkey->keyid & 0xFFFFFFFF,
- txt2html(keyid2uid(curkey->keyid)),
+ txt2html(uid),
(curkey->keyid == want) ? "" :
" signs");
} else {
(curkey->keyid == want) ? "" :
" signs");
}
+ if (uid != NULL) {
+ free(uid);
+ uid = NULL;
+ }
curkey = findinhash(curkey->parent);
}
if (html) {