Browse Source

common/daemon: enable/cleanup memleak in daemon_setup / daemon_shutdown.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
trytravis
Rusty Russell 6 years ago
parent
commit
5a81dbd783
  1. 10
      common/daemon.c
  2. 1
      connectd/Makefile
  3. 1
      gossipd/Makefile
  4. 1
      hsmd/Makefile
  5. 20
      lightningd/lightningd.c

10
common/daemon.c

@ -5,6 +5,7 @@
#include <ccan/io/io.h>
#include <ccan/str/str.h>
#include <common/daemon.h>
#include <common/memleak.h>
#include <common/status.h>
#include <common/utils.h>
#include <common/version.h>
@ -126,6 +127,12 @@ void daemon_setup(const char *argv0,
crashlog_activate();
#endif
#if DEVELOPER
/* This has significant overhead, so we only enable it if told */
if (getenv("LIGHTNINGD_DEV_MEMLEAK"))
memleak_init();
#endif
/* We handle write returning errors! */
signal(SIGPIPE, SIG_IGN);
wally_init(0);
@ -137,6 +144,9 @@ void daemon_setup(const char *argv0,
void daemon_shutdown(void)
{
#if DEVELOPER
memleak_cleanup();
#endif
tal_free(tmpctx);
wally_cleanup(0);
}

1
connectd/Makefile

@ -49,6 +49,7 @@ CONNECTD_COMMON_OBJS := \
common/dev_disconnect.o \
common/features.o \
common/gen_status_wire.o \
common/memleak.o \
common/msg_queue.o \
common/pseudorand.o \
common/status.o \

1
gossipd/Makefile

@ -49,6 +49,7 @@ GOSSIPD_COMMON_OBJS := \
common/dev_disconnect.o \
common/features.o \
common/gen_status_wire.o \
common/memleak.o \
common/msg_queue.o \
common/ping.o \
common/pseudorand.o \

1
hsmd/Makefile

@ -21,6 +21,7 @@ HSMD_COMMON_OBJS := \
common/gen_status_wire.o \
common/hash_u5.o \
common/key_derive.o \
common/memleak.o \
common/msg_queue.o \
common/permute_tx.o \
common/status.o \

20
lightningd/lightningd.c

@ -57,7 +57,6 @@
/*~ This is common code: routines shared by one or more executables
* (separate daemons, or the lightning-cli program). */
#include <common/daemon.h>
#include <common/memleak.h>
#include <common/timeout.h>
#include <common/utils.h>
#include <common/version.h>
@ -116,15 +115,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_disconnect_fd = -1;
ld->dev_subdaemon_fail = false;
ld->dev_allow_localhost = false;
/*~ Behaving differently depending on environment variables is a hack,
* *but* hacks are allowed for dev-mode stuff. In this case, there's
* a significant overhead to the memory leak detection stuff, and we
* can't use it under valgrind (an awesome runtime memory usage
* detector for C and C++ programs), so the test harness uses this var
* to disable it in that case. */
if (getenv("LIGHTNINGD_DEV_MEMLEAK"))
memleak_init();
#endif
/*~ These are CCAN lists: an embedded double-linked list. It's not
@ -374,9 +364,10 @@ static const char *find_daemon_dir(const tal_t *ctx, const char *argv0)
return find_my_pkglibexec_path(ctx, take(my_path));
}
/*~ We like to free everything on exit, so valgrind doesn't complain. In some
* ways it would be neater not to do this, but it turns out some transient
* objects still need cleaning. */
/*~ We like to free everything on exit, so valgrind doesn't complain (valgrind
* is an awesome runtime memory usage detector for C and C++ programs). In
* some ways it would be neater not to do this, but it turns out some
* transient objects still need cleaning. */
static void shutdown_subdaemons(struct lightningd *ld)
{
struct peer *p;
@ -798,9 +789,6 @@ int main(int argc, char *argv[])
tal_free(ld);
opt_free_table();
#if DEVELOPER
memleak_cleanup();
#endif
daemon_shutdown();
/*~ Farewell. Next stop: hsmd/hsmd.c. */

Loading…
Cancel
Save