diff --git a/channeld/channel.c b/channeld/channel.c index 37c481f4e..8e42f082f 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -2753,6 +2753,6 @@ int main(int argc, char *argv[]) /* We only exit when shutdown is complete. */ assert(shutdown_complete(peer)); send_shutdown_complete(peer); - tal_free(tmpctx); + subdaemon_shutdown(); return 0; } diff --git a/closingd/closing.c b/closingd/closing.c index c3cf7959e..8e8f06423 100644 --- a/closingd/closing.c +++ b/closingd/closing.c @@ -577,7 +577,7 @@ int main(int argc, char *argv[]) wire_sync_write(REQ_FD, take(towire_closing_complete(NULL, gossip_index))); tal_free(ctx); - tal_free(tmpctx); + subdaemon_shutdown(); return 0; } diff --git a/common/subdaemon.c b/common/subdaemon.c index b3d6564bb..220dffed9 100644 --- a/common/subdaemon.c +++ b/common/subdaemon.c @@ -101,3 +101,9 @@ void subdaemon_setup(int argc, char *argv[]) } #endif } + +void subdaemon_shutdown(void) +{ + tal_free(tmpctx); + secp256k1_context_destroy(secp256k1_ctx); +} diff --git a/common/subdaemon.h b/common/subdaemon.h index 3722493e1..9939f1491 100644 --- a/common/subdaemon.h +++ b/common/subdaemon.h @@ -4,4 +4,7 @@ void subdaemon_setup(int argc, char *argv[]); +/* Shutdown for a valgrind-clean exit (frees everything) */ +void subdaemon_shutdown(void); + #endif /* LIGHTNING_COMMON_SUBDAEMON_H */ diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 30f382c46..17343d9b1 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -2147,6 +2147,7 @@ int main(int argc, char *argv[]) timer_expired(daemon, expired); } } + subdaemon_shutdown(); return 0; } #endif diff --git a/hsmd/hsm.c b/hsmd/hsm.c index dc5845356..bf0058bdb 100644 --- a/hsmd/hsm.c +++ b/hsmd/hsm.c @@ -842,6 +842,8 @@ int main(int argc, char *argv[]) /* When conn closes, everything is freed. */ tal_steal(client->dc.conn, client); io_loop(NULL, NULL); + subdaemon_shutdown(); + return 0; } #endif diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 2d2f47fbf..4ba55d8d9 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -2315,7 +2315,7 @@ int main(int argc, char *argv[]) /* We're done! */ tal_free(ctx); - tal_free(tmpctx); + subdaemon_shutdown(); return 0; } diff --git a/openingd/opening.c b/openingd/opening.c index 03b427388..0094f1d14 100644 --- a/openingd/opening.c +++ b/openingd/opening.c @@ -776,7 +776,7 @@ int main(int argc, char *argv[]) status_trace("Sent %s with fd", opening_wire_type_name(fromwire_peektype(msg))); tal_free(state); - tal_free(tmpctx); + subdaemon_shutdown(); return 0; } #endif /* TESTING */