Always set keyring to NULL after use.

This commit is contained in:
Jeremy Lakeman 2014-05-15 15:51:02 +09:30
parent 5463feeff7
commit 9e267ece21
2 changed files with 39 additions and 0 deletions

View File

@ -300,6 +300,8 @@ int parseCommandLine(struct cli_context *context, const char *argv0, int argc, c
/* clean up after ourselves */
rhizome_close_db();
free_subscribers();
assert(keyring==NULL);
OUT();
if (config.debug.timing)
@ -1664,6 +1666,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
if (rhizome_opendb() == -1){
keyring_free(keyring);
keyring = NULL;
return -1;
}
@ -1672,6 +1675,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
rhizome_manifest *m = rhizome_new_manifest();
if (!m){
keyring_free(keyring);
keyring = NULL;
return WHY("Manifest struct could not be allocated -- not added to rhizome");
}
if (manifestpath && *manifestpath && access(manifestpath, R_OK) == 0) {
@ -1684,6 +1688,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
if (rhizome_read_manifest_from_file(m, manifestpath) || m->malformed) {
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return WHY("Manifest file could not be loaded -- not added to rhizome");
}
} else if (manifestid && *manifestid) {
@ -1693,11 +1698,13 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
if (str_to_rhizome_bid_t(&bid, manifestid) == -1) {
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return WHYF("Invalid bundle ID: %s", alloca_str_toprint(manifestid));
}
if (rhizome_retrieve_manifest(&bid, m)){
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return WHY("Existing manifest could not be loaded -- not added to rhizome");
}
} else {
@ -1712,11 +1719,13 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
if (journal && !m->is_journal){
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return WHY("Existing manifest is not a journal");
}
if (!journal && m->is_journal) {
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return WHY("Existing manifest is a journal");
}
@ -1727,6 +1736,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
if (rhizome_fill_manifest(m, filepath, *authorSidHex ? &authorSid : NULL)) {
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return -1;
}
@ -1801,6 +1811,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
}
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return status;
}
@ -1881,22 +1892,26 @@ int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *UNUS
if (cli_arg(parsed, "file", NULL, NULL, NULL) == 0) {
if (!fileid){
keyring_free(keyring);
keyring = NULL;
return WHY("missing <fileid> argument");
}
rhizome_filehash_t hash;
if (str_to_rhizome_filehash_t(&hash, fileid) == -1){
keyring_free(keyring);
keyring = NULL;
return WHYF("invalid <fileid> argument: %s", alloca_str_toprint(fileid));
}
ret = rhizome_delete_file(&hash);
} else {
if (!manifestid){
keyring_free(keyring);
keyring = NULL;
return WHY("missing <manifestid> argument");
}
rhizome_bid_t bid;
if (str_to_rhizome_bid_t(&bid, manifestid) == -1){
keyring_free(keyring);
keyring = NULL;
return WHY("Invalid manifest ID");
}
if (cli_arg(parsed, "bundle", NULL, NULL, NULL) == 0)
@ -1907,10 +1922,12 @@ int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *UNUS
ret = rhizome_delete_payload(&bid);
else{
keyring_free(keyring);
keyring = NULL;
return WHY("unrecognised command");
}
}
keyring_free(keyring);
keyring = NULL;
return ret;
}
@ -1960,6 +1977,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
rhizome_bid_t bid;
if (str_to_rhizome_bid_t(&bid, manifestid) == -1){
keyring_free(keyring);
keyring = NULL;
return WHY("Invalid manifest ID");
}
@ -1970,12 +1988,14 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
rhizome_bk_t bsk;
if (bskhex && str_to_rhizome_bk_t(&bsk, bskhex) == -1){
keyring_free(keyring);
keyring = NULL;
return WHYF("invalid bsk: \"%s\"", bskhex);
}
rhizome_manifest *m = rhizome_new_manifest();
if (m==NULL){
keyring_free(keyring);
keyring = NULL;
return WHY("Out of manifests");
}
ret = rhizome_retrieve_manifest(&bid, m);
@ -2038,6 +2058,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
if (m)
rhizome_manifest_free(m);
keyring_free(keyring);
keyring = NULL;
return ret;
}
@ -2099,6 +2120,7 @@ int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *contex
return -1;
if (rhizome_opendb() == -1) {
keyring_free(keyring);
keyring = NULL;
return -1;
}
size_t rowlimit = atoi(limit_ascii);
@ -2119,6 +2141,7 @@ int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *contex
}
if (rhizome_list_open(&cursor) == -1) {
keyring_free(keyring);
keyring = NULL;
return -1;
}
const char *headers[]={
@ -2173,6 +2196,7 @@ int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *contex
}
rhizome_list_release(&cursor);
keyring_free(keyring);
keyring = NULL;
if (n == -1)
return -1;
cli_row_count(context, rowcount);
@ -2386,6 +2410,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con
sid_t sid;
if (str_to_sid_t(&sid, sidhex) == -1){
keyring_free(keyring);
keyring = NULL;
return WHY("str_to_sid_t() failed");
}
@ -2409,6 +2434,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con
}
keyring_free(keyring);
keyring = NULL;
return r;
}
@ -2445,6 +2471,7 @@ static int app_keyring_set_tag(const struct cli_parsed *parsed, struct cli_conte
}
keyring_free(keyring);
keyring = NULL;
return r;
}

View File

@ -974,6 +974,7 @@ int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context
return -1;
if (rhizome_opendb() == -1){
keyring_free(keyring);
keyring = NULL;
return -1;
}
@ -981,6 +982,7 @@ int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context
enum meshms_status status;
if (meshms_failed(status = meshms_conversations_list(&sid, NULL, &conv))) {
keyring_free(keyring);
keyring = NULL;
return status;
}
const char *names[]={
@ -1008,6 +1010,7 @@ int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context
meshms_free_conversations(conv);
keyring_free(keyring);
keyring = NULL;
return 0;
}
@ -1025,6 +1028,7 @@ int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context
return -1;
if (rhizome_opendb() == -1){
keyring_free(keyring);
keyring = NULL;
return -1;
}
@ -1036,6 +1040,7 @@ int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context
// include terminating NUL
enum meshms_status status = meshms_send_message(&my_sid, &their_sid, message, strlen(message) + 1);
keyring_free(keyring);
keyring = NULL;
return meshms_failed(status) ? status : 0;
}
@ -1051,21 +1056,25 @@ int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_context
return -1;
if (rhizome_opendb() == -1){
keyring_free(keyring);
keyring = NULL;
return -1;
}
sid_t my_sid, their_sid;
if (str_to_sid_t(&my_sid, my_sidhex) == -1){
keyring_free(keyring);
keyring = NULL;
return WHY("invalid sender SID");
}
if (str_to_sid_t(&their_sid, their_sidhex) == -1){
keyring_free(keyring);
keyring = NULL;
return WHY("invalid recipient SID");
}
struct meshms_message_iterator iter;
enum meshms_status status;
if (meshms_failed(status = meshms_message_iterator_open(&iter, &my_sid, &their_sid))) {
keyring_free(keyring);
keyring = NULL;
return status;
}
const char *names[]={
@ -1113,6 +1122,7 @@ int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_context
cli_row_count(context, id);
meshms_message_iterator_close(&iter);
keyring_free(keyring);
keyring = NULL;
return status;
}
@ -1164,6 +1174,7 @@ int app_meshms_mark_read(const struct cli_parsed *parsed, struct cli_context *UN
return -1;
if (rhizome_opendb() == -1){
keyring_free(keyring);
keyring = NULL;
return -1;
}
sid_t my_sid, their_sid;
@ -1199,5 +1210,6 @@ end:
rhizome_manifest_free(m);
meshms_free_conversations(conv);
keyring_free(keyring);
keyring = NULL;
return status;
}