Skip to content

Commit

Permalink
utils: add subdaemon_shutdown() to consolidate subdaemon cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Apr 3, 2018
1 parent 26f7014 commit 20bbd92
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion channeld/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion closingd/closing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions common/subdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ void subdaemon_setup(int argc, char *argv[])
}
#endif
}

void subdaemon_shutdown(void)
{
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
}
3 changes: 3 additions & 0 deletions common/subdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
1 change: 1 addition & 0 deletions gossipd/gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,7 @@ int main(int argc, char *argv[])
timer_expired(daemon, expired);
}
}
subdaemon_shutdown();
return 0;
}
#endif
2 changes: 2 additions & 0 deletions hsmd/hsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion onchaind/onchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ int main(int argc, char *argv[])

/* We're done! */
tal_free(ctx);
tal_free(tmpctx);
subdaemon_shutdown();

return 0;
}
2 changes: 1 addition & 1 deletion openingd/opening.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 20bbd92

Please sign in to comment.