Skip to content

Commit

Permalink
lightningd: add code to search strmaps for memleak detection.
Browse files Browse the repository at this point in the history
Didn't put this in common/memleak because only lightningd currently needs it
(as of next patch).

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 7, 2019
1 parent c506d42 commit e5c80f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
17 changes: 17 additions & 0 deletions lightningd/memdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions lightningd/memdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit e5c80f6

Please sign in to comment.