Skip to content

Commit

Permalink
lightningd: help memleak scan into replay_tx hash table to avoid fals…
Browse files Browse the repository at this point in the history
…e positives.

```
**BROKEN** lightningd: MEMLEAK: 0x5557327d1428
**BROKEN** lightningd:   label=lightningd/onchain_control.c:352:struct replay_tx
**BROKEN** lightningd:   alloc:
**BROKEN** lightningd:     /home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:488 (tal_alloc_)
**BROKEN** lightningd:     /home/runner/work/lightning/lightning/lightningd/onchain_control.c:352 (replay_watch_tx)
**BROKEN** lightningd:     /home/runner/work/lightning/lightning/lightningd/onchain_control.c:1816 (onchaind_funding_spent)
**BROKEN** lightningd:     /home/runner/work/lightning/lightning/lightningd/onchain_control.c:1860 (onchaind_replay_channels)
**BROKEN** lightningd:     /home/runner/work/lightning/lightning/lightningd/lightningd.c:1407 (main)
**BROKEN** lightningd:   parents:
**BROKEN** lightningd:     lightningd/onchain_control.c:1856:struct replay_tx_hash
**BROKEN** lightningd:     lightningd/lightningd.c:112:struct lightningd
```

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Nov 17, 2024
1 parent a0f20de commit d39e7ea
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lightningd/onchain_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
#include <common/htlc_tx.h>
#include <common/memleak.h>
#include <common/key_derive.h>
#include <common/psbt_keypath.h>
#include <db/exec.h>
Expand Down Expand Up @@ -47,6 +48,13 @@ static bool replay_tx_eq_txid(const struct replay_tx *rtx,
HTABLE_DEFINE_TYPE(struct replay_tx, replay_tx_keyof, txid_hash, replay_tx_eq_txid,
replay_tx_hash);

/* Helper for memleak detection */
static void memleak_replay_tx_hash(struct htable *memtable,
struct replay_tx_hash *replay_tx_hash)
{
memleak_scan_htable(memtable, &replay_tx_hash->raw);
}

/* We dump all the known preimages when onchaind starts up. */
static void onchaind_tell_fulfill(struct channel *channel)
{
Expand Down Expand Up @@ -1856,6 +1864,8 @@ void onchaind_replay_channels(struct lightningd *ld)
channel->onchaind_replay_watches = tal(channel, struct replay_tx_hash);
channel->onchaind_replay_height = blockheight;
replay_tx_hash_init(channel->onchaind_replay_watches);
memleak_add_helper(channel->onchaind_replay_watches,
memleak_replay_tx_hash);

onchaind_funding_spent(channel, tx, blockheight);
onchaind_replay(channel);
Expand Down

0 comments on commit d39e7ea

Please sign in to comment.