diff --git a/keyring.c b/keyring.c index d45f43b6..a6911f1e 100644 --- a/keyring.c +++ b/keyring.c @@ -2046,29 +2046,43 @@ int keyring_load_from_dump(keyring_file *k, unsigned entry_pinc, const char **en line[--linelen] = '\0'; if (linelen && line[linelen - 1] == '\r') line[--linelen] = '\0'; - } else + } else { + if (id) + keyring_free_identity(id); return WHY("line too long"); + } unsigned idn; unsigned ktype; int i, j; int n = sscanf(line, "%u: type=%u (%n%*[^)]%n)", &idn, &ktype, &i, &j); if (n == EOF && (ferror(input) || feof(input))) break; - if (n != 2) + if (n != 2){ + if (id) + keyring_free_identity(id); return WHYF("malformed input n=%u", n); - if (ktype == 0) + } + if (ktype == 0){ + if (id) + keyring_free_identity(id); return WHY("invalid input: ktype=0"); + } const char *ktypestr = &line[i]; line[j] = '\0'; const char *content = &line[j + 1]; //DEBUGF(keyring, "n=%d i=%u ktypestr=%s j=%u content=%s", n, i, alloca_str_toprint(ktypestr), j, alloca_str_toprint(content)); keypair *kp = keyring_alloc_keypair(ktype, 0); - if (kp == NULL) + if (kp == NULL){ + if (id) + keyring_free_identity(id); return -1; + } int (*loader)(keypair *, const char *) = load_unknown; if (strcmp(ktypestr, "unknown") != 0 && ktype < NELS(keytypes)) loader = keytypes[ktype].loader; if (loader(kp, content) == -1) { + if (id) + keyring_free_identity(id); keyring_free_keypair(kp); return -1; } diff --git a/meshms.c b/meshms.c index cea1ae27..5cb857e6 100644 --- a/meshms.c +++ b/meshms.c @@ -755,12 +755,14 @@ enum meshms_status meshms_message_iterator_open(struct meshms_message_iterator * c = c->_next; } + rhizome_manifest_free(m); meshms_free_conversations(conv); return MESHMS_STATUS_OK; error: status = MESHMS_STATUS_ERROR; fail: + rhizome_manifest_free(m); meshms_message_iterator_close(iter); meshms_free_conversations(conv); return status; diff --git a/network_cli.c b/network_cli.c index e841758d..edaeb380 100644 --- a/network_cli.c +++ b/network_cli.c @@ -287,6 +287,9 @@ static int app_trace(const struct cli_parsed *parsed, struct cli_context *contex struct mdp_header mdp_header; bzero(&mdp_header, sizeof mdp_header); + uint8_t payload[MDP_MTU]; + struct overlay_buffer *b = ob_static(payload, sizeof payload); + mdp_header.local.sid = BIND_PRIMARY; if (mdp_bind(mdp_sockfd, &mdp_header.local)) @@ -304,8 +307,6 @@ static int app_trace(const struct cli_parsed *parsed, struct cli_context *contex cli_delim(context, "\n"); cli_flush(context); time_ms_t end_time = gettime_ms() + timeout_ms; - uint8_t payload[MDP_MTU]; - struct overlay_buffer *b = ob_static(payload, sizeof payload); while(1){ ob_clear(b); @@ -354,6 +355,8 @@ static int app_trace(const struct cli_parsed *parsed, struct cli_context *contex end: + if (b) + ob_free(b); mdp_close(mdp_sockfd); return ret; } diff --git a/overlay_address.c b/overlay_address.c index 2439f021..c8708043 100644 --- a/overlay_address.c +++ b/overlay_address.c @@ -447,8 +447,10 @@ int send_please_explain(struct decode_context *context, struct subscriber *sourc frame_add_destination(frame, NULL, context->interface->destination); struct network_destination *dest = create_unicast_destination(&context->addr, context->interface); - if (dest) + if (dest){ frame_add_destination(frame, NULL, dest); + release_destination_ref(dest); + } }else{ FATAL("This context doesn't have an interface?"); diff --git a/overlay_interface.c b/overlay_interface.c index 12a184f1..24d7f58f 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -90,6 +90,9 @@ void overlay_interface_close(overlay_interface *interface) unschedule(&interface->alarm); if (interface->radio_link_state) radio_link_free(interface); + + set_destination_ref(&interface->destination, NULL); + interface->state=INTERFACE_STATE_DOWN; INFOF("Interface %s addr %s is down", diff --git a/overlay_mdp.c b/overlay_mdp.c index c80b3402..92faa287 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -874,8 +874,8 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h /* crypted and signed (using CryptoBox authcryption primitive) */ frame->payload = encrypt_payload(frame->source, frame->destination, ob_ptr(plaintext), ob_position(plaintext)); + ob_free(plaintext); if (!frame->payload){ - ob_free(plaintext); op_free(frame); return -1; } diff --git a/overlay_queue.c b/overlay_queue.c index 3904e112..5c5fd9c8 100644 --- a/overlay_queue.c +++ b/overlay_queue.c @@ -62,7 +62,7 @@ static int overlay_calc_queue_time(struct overlay_frame *frame); int overlay_queue_init(){ /* Set default congestion levels for queues */ - int i; + unsigned i; for(i=0;ibuffer); (*c)->buffer=NULL; + free((*c)->buffer); + (*c)->buffer=NULL; bzero(*c,sizeof(rhizome_direct_bundle_cursor)); + free(*c); *c=NULL; } diff --git a/rhizome_direct_cli.c b/rhizome_direct_cli.c index 726bcb95..ca039ccd 100644 --- a/rhizome_direct_cli.c +++ b/rhizome_direct_cli.c @@ -55,12 +55,16 @@ static int rhizome_sync_with_peers(int mode, int peer_count, const struct config int peer_number; for (peer_number = 0; peer_number < peer_count; ++peer_number) { const struct config_rhizome_peer *peer = peers[peer_number]; - if (strcasecmp(peer->protocol, "http") != 0) + if (strcasecmp(peer->protocol, "http") != 0){ + free(state); return WHYF("Unsupported Rhizome Direct protocol %s", alloca_str_toprint(peer->protocol)); + } strbuf h = strbuf_local(state->host, sizeof state->host); strbuf_puts(h, peer->host); - if (strbuf_overrun(h)) + if (strbuf_overrun(h)){ + free(state); return WHYF("Rhizome Direct host name too long: %s", alloca_str_toprint(peer->host)); + } state->port = peer->port; DEBUGF(rhizome_direct, "Rhizome direct peer is %s://%s:%d", peer->protocol, state->host, state->port); rhizome_direct_sync_request *s = rhizome_direct_new_sync_request(rhizome_direct_http_dispatch, 65536, 0, mode, state); @@ -69,6 +73,7 @@ static int rhizome_sync_with_peers(int mode, int peer_count, const struct config while (fd_poll() && rd_sync_handle_count > 0) ; } + free(state); return 0; } diff --git a/rhizome_sync_keys.c b/rhizome_sync_keys.c index 920a2b68..104ec9cc 100644 --- a/rhizome_sync_keys.c +++ b/rhizome_sync_keys.c @@ -621,6 +621,7 @@ void sync_send_keys(struct sched_ent *alarm) header.qos = OQ_OPPORTUNISTIC; header.ttl = 1; overlay_send_frame(&header, payload); + ob_free(payload); time_ms_t now = gettime_ms(); diff --git a/serval.h b/serval.h index e3b86d85..7254657b 100644 --- a/serval.h +++ b/serval.h @@ -261,6 +261,7 @@ int overlay_send_stun_request(struct subscriber *server, struct subscriber *requ void rhizome_check_connections(struct sched_ent *alarm); int overlay_queue_init(); +void overlay_queue_release(); void monitor_client_poll(struct sched_ent *alarm); void monitor_poll(struct sched_ent *alarm); diff --git a/server.c b/server.c index 976e1582..6b0ae8b2 100644 --- a/server.c +++ b/server.c @@ -671,6 +671,7 @@ static void serverCleanUp() { assert(serverMode != SERVER_NOT_RUNNING); INFOF("Server cleaning up"); + overlay_queue_release(); rhizome_close_db(); dna_helper_shutdown(); overlay_interface_close_all(); diff --git a/simulator.c b/simulator.c index f50629f1..fcfdd358 100644 --- a/simulator.c +++ b/simulator.c @@ -599,6 +599,13 @@ int main() DEBUGF(verbose, "Closing peer proxy socket, TX %d RX %d", p->tx_count, p->rx_count); unwatch(&p->alarm); socket_unlink_close(p->alarm.poll.fd); + + while(p->_head){ + struct packet *packet = p->_head; + p->_head = packet->_next; + free(packet); + } + struct peer *f = p; p=p->_next; free(f); diff --git a/testframework.sh b/testframework.sh index 56d65aee..b2e5b7d9 100644 --- a/testframework.sh +++ b/testframework.sh @@ -1761,6 +1761,7 @@ tfw_quietly() { execute() { $_tfw_assert_noise && tfw_log "# execute" $(shellarg "$@") _tfw_getopts execute "$@" + _tfw_dump_on_fail --stderr shift $_tfw_getopts_shift _tfw_execute "$@" } @@ -1769,7 +1770,6 @@ executeOk() { $_tfw_assert_noise && tfw_log "# executeOk" $(shellarg "$@") _tfw_getopts executeok "$@" _tfw_opt_exit_status=0 - _tfw_dump_on_fail --stderr shift $_tfw_getopts_shift _tfw_execute "$@" }