wallet: do proper memleak scan of outpoint htables, not notleak().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-12-20 15:37:07 +10:30
parent 2f64283945
commit d6217e2835
7 changed files with 36 additions and 6 deletions

View file

@ -201,6 +201,7 @@ static bool lightningd_check_leaks(struct command *cmd)
memleak_scan_htable(memtable, &ld->htlc_sets->raw);
memleak_scan_htable(memtable, &ld->peers->raw);
memleak_scan_htable(memtable, &ld->peers_by_dbid->raw);
wallet_memleak_scan(memtable, ld->wallet);
/* Now delete ld and those which it has pointers to. */
memleak_scan_obj(memtable, ld);

View file

@ -121,6 +121,10 @@ struct invoices *invoices_new(const tal_t *ctx UNNEEDED,
void logv(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const struct node_id *node_id UNNEEDED,
bool call_notifier UNNEEDED, const char *fmt UNNEEDED, va_list ap UNNEEDED)
{ fprintf(stderr, "logv called!\n"); abort(); }
/* Generated stub for memleak_scan_outpointfilter */
void memleak_scan_outpointfilter(struct htable *memtable UNNEEDED,
const struct outpointfilter *opf UNNEEDED)
{ fprintf(stderr, "memleak_scan_outpointfilter called!\n"); abort(); }
/* Generated stub for new_channel */
struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
/* NULL or stolen */

View file

@ -626,6 +626,10 @@ void lockin_complete(struct channel *channel UNNEEDED,
void logv(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const struct node_id *node_id UNNEEDED,
bool call_notifier UNNEEDED, const char *fmt UNNEEDED, va_list ap UNNEEDED)
{ fprintf(stderr, "logv called!\n"); abort(); }
/* Generated stub for memleak_scan_outpointfilter */
void memleak_scan_outpointfilter(struct htable *memtable UNNEEDED,
const struct outpointfilter *opf UNNEEDED)
{ fprintf(stderr, "memleak_scan_outpointfilter called!\n"); abort(); }
/* Generated stub for new_channel_mvt_invoice_hin */
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx UNNEEDED,
struct htlc_in *hin UNNEEDED,

View file

@ -103,11 +103,9 @@ void outpointfilter_add(struct outpointfilter *of,
{
if (outpointfilter_matches(of, outpoint))
return;
/* Have to mark the entries as notleak since they'll not be
* pointed to by anything other than the htable */
outpointset_add(of->set, notleak(tal_dup(of->set,
struct bitcoin_outpoint,
outpoint)));
outpointset_add(of->set, tal_dup(of->set,
struct bitcoin_outpoint,
outpoint));
}
bool outpointfilter_matches(struct outpointfilter *of,
@ -119,7 +117,11 @@ bool outpointfilter_matches(struct outpointfilter *of,
void outpointfilter_remove(struct outpointfilter *of,
const struct bitcoin_outpoint *outpoint)
{
outpointset_del(of->set, outpoint);
struct bitcoin_outpoint *o = outpointset_get(of->set, outpoint);
if (o) {
outpointset_del(of->set, o);
tal_free(o);
}
}
struct outpointfilter *outpointfilter_new(tal_t *ctx)
@ -129,3 +131,8 @@ struct outpointfilter *outpointfilter_new(tal_t *ctx)
outpointset_init(opf->set);
return opf;
}
void memleak_scan_outpointfilter(struct htable *memtable, const struct outpointfilter *opf)
{
memleak_scan_htable(memtable, &opf->set->raw);
}

View file

@ -64,4 +64,6 @@ bool outpointfilter_matches(struct outpointfilter *of,
void outpointfilter_remove(struct outpointfilter *of,
const struct bitcoin_outpoint *outpoint);
void memleak_scan_outpointfilter(struct htable *memtable,
const struct outpointfilter *opf);
#endif /* LIGHTNING_WALLET_TXFILTER_H */

View file

@ -6416,6 +6416,12 @@ struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx,
return anchors;
}
void wallet_memleak_scan(struct htable *memtable, const struct wallet *w)
{
memleak_scan_outpointfilter(memtable, w->utxoset_outpoints);
memleak_scan_outpointfilter(memtable, w->owned_outpoints);
}
struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet,
u64 liststart, const u32 *listlimit)
{

View file

@ -1817,4 +1817,10 @@ struct issued_address_type {
*/
struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet,
u64 liststart, const u32 *listlimit);
/**
* wallet_memleak_scan - Check for memleaks in wallet.
*/
void wallet_memleak_scan(struct htable *memtable, const struct wallet *w);
#endif /* LIGHTNING_WALLET_WALLET_H */