utils: add subdaemon_shutdown() to consolidate subdaemon cleanup.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-03-28 13:00:49 +10:30
committed by Christian Decker
parent 26f7014813
commit 20bbd92564
8 changed files with 16 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -101,3 +101,9 @@ void subdaemon_setup(int argc, char *argv[])
}
#endif
}
void subdaemon_shutdown(void)
{
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
}

View File

@@ -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 */

View File

@@ -2147,6 +2147,7 @@ int main(int argc, char *argv[])
timer_expired(daemon, expired);
}
}
subdaemon_shutdown();
return 0;
}
#endif

View File

@@ -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

View File

@@ -2315,7 +2315,7 @@ int main(int argc, char *argv[])
/* We're done! */
tal_free(ctx);
tal_free(tmpctx);
subdaemon_shutdown();
return 0;
}

View File

@@ -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 */