lightningd: fix backtraces in memleak detection.

We were using a *different* backtrace_state var, which was always NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-08-24 13:36:37 +09:30 committed by Christian Decker
parent c02ab124aa
commit 12a39b8a79
7 changed files with 9 additions and 12 deletions

View File

@ -15,8 +15,9 @@
#include <unistd.h>
#include <wally_core.h>
struct backtrace_state *backtrace_state;
#if BACKTRACE_SUPPORTED
static struct backtrace_state *backtrace_state;
static void (*bt_print)(const char *fmt, ...) PRINTF_FMT(1,2);
static void (*bt_exit)(void);

View File

@ -10,4 +10,6 @@ void daemon_setup(const char *argv0,
/* Shutdown for a valgrind-clean exit (frees everything) */
void daemon_shutdown(void);
struct backtrace_state *backtrace_state;
#endif /* LIGHTNING_COMMON_DAEMON_H */

View File

@ -2,10 +2,10 @@
#include <backtrace.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/htable/htable.h>
#include <common/daemon.h>
#include <common/memleak.h>
#if DEVELOPER
static struct backtrace_state *backtrace_state;
static const void **notleaks;
static bool *notleak_children;
@ -226,10 +226,9 @@ static void add_backtrace(tal_t *parent UNUSED, enum tal_notify_type type UNNEED
tal_add_notifier(child, TAL_NOTIFY_ADD_CHILD, add_backtrace);
}
void memleak_init(const tal_t *root, struct backtrace_state *bstate)
void memleak_init(const tal_t *root)
{
assert(!notleaks);
backtrace_state = bstate;
notleaks = tal_arr(NULL, const void *, 0);
notleak_children = tal_arr(notleaks, bool, 0);

View File

@ -21,10 +21,9 @@
void *notleak_(const void *ptr, bool plus_children);
struct htable;
struct backtrace_state;
/* Initialize memleak detection, with this as the root */
void memleak_init(const tal_t *root, struct backtrace_state *bstate);
void memleak_init(const tal_t *root);
/* Free memleak detection. */
void memleak_cleanup(void);

View File

@ -41,8 +41,6 @@
char *bitcoin_datadir;
struct backtrace_state *backtrace_state;
int pid_fd;
static struct lightningd *new_lightningd(const tal_t *ctx)
@ -56,7 +54,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_allow_localhost = false;
if (getenv("LIGHTNINGD_DEV_MEMLEAK"))
memleak_init(ld, backtrace_state);
memleak_init(ld);
#endif
list_head_init(&ld->peers);

View File

@ -204,9 +204,6 @@ struct lightningd {
const struct chainparams *get_chainparams(const struct lightningd *ld);
/* State for performing backtraces. */
struct backtrace_state *backtrace_state;
/* Check we can run subdaemons, and check their versions */
void test_daemons(const struct lightningd *ld);

View File

@ -3,6 +3,7 @@
#if DEVELOPER
#include <backtrace.h>
#include <ccan/tal/str/str.h>
#include <common/daemon.h>
#include <common/memleak.h>
#include <lightningd/chaintopology.h>
#include <lightningd/jsonrpc.h>