Browse Source

lightningd: add code to search strmaps for memleak detection.

Didn't put this in common/memleak because only lightningd currently needs it
(as of next patch).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fix-test_pay_direct-flake
Rusty Russell 6 years ago
parent
commit
e5c80f63d7
  1. 1
      Makefile
  2. 17
      lightningd/memdump.c
  3. 8
      lightningd/memdump.h

1
Makefile

@ -96,6 +96,7 @@ CCAN_OBJS := \
ccan-str-base32.o \
ccan-str-hex.o \
ccan-str.o \
ccan-strmap.o \
ccan-take.o \
ccan-tal-grab_file.o \
ccan-tal-link.o \

17
lightningd/memdump.c

@ -2,6 +2,7 @@
#include "memdump.h"
#if DEVELOPER
#include <backtrace.h>
#include <ccan/strmap/strmap.h>
#include <ccan/tal/str/str.h>
#include <common/daemon.h>
#include <common/json_command.h>
@ -120,6 +121,22 @@ static void json_add_backtrace(struct json_stream *response,
json_array_end(response);
}
static bool handle_strmap(const char *member, void *p, void *memtable_)
{
struct htable *memtable = memtable_;
memleak_scan_region(memtable, p, tal_bytelen(p));
/* Keep going */
return true;
}
/* FIXME: If strmap used tal, this wouldn't be necessary! */
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m)
{
strmap_iterate_(m, handle_strmap, memtable);
}
static void scan_mem(struct command *cmd,
struct json_stream *response,
struct lightningd *ld,

8
lightningd/memdump.h

@ -5,8 +5,16 @@
#include <stdbool.h>
struct command;
struct htable;
struct strmap;
struct subd;
void opening_memleak_done(struct command *cmd, struct subd *leaker);
void peer_memleak_done(struct command *cmd, struct subd *leaker);
/* Remove any pointers inside this strmap (which is opaque to memleak). */
#define memleak_remove_strmap(memtable, strmap) \
memleak_remove_strmap_((memtable), tcon_unwrap(strmap))
void memleak_remove_strmap_(struct htable *memtable, const struct strmap *m);
#endif /* LIGHTNING_LIGHTNINGD_MEMDUMP_H */

Loading…
Cancel
Save