From 396c40698363cf6a6271644fbbca381fe6b5cd89 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 22 Oct 2020 13:24:46 -0500 Subject: [PATCH] dualopend: re-order 'handle_dev_memleak' occurrence --- openingd/dualopend.c | 67 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/openingd/dualopend.c b/openingd/dualopend.c index d991e17ff..18053f4b8 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -597,6 +597,40 @@ static bool is_segwit_output(struct wally_tx_output *output, return is_p2wsh(wit_prog, NULL) || is_p2wpkh(wit_prog, NULL); } +/* Memory leak detection is DEVELOPER-only because we go to great lengths to + * record the backtrace when allocations occur: without that, the leak + * detection tends to be useless for diagnosing where the leak came from, but + * it has significant overhead. */ +#if DEVELOPER +static void handle_dev_memleak(struct state *state, const u8 *msg) +{ + struct htable *memtable; + bool found_leak; + + /* Populate a hash table with all our allocations (except msg, which + * is in use right now). */ + memtable = memleak_find_allocations(tmpctx, msg, msg); + + /* Now delete state and things it has pointers to. */ + memleak_remove_region(memtable, state, tal_bytelen(state)); + + /* If there's anything left, dump it to logs, and return true. */ + found_leak = dump_memleak(memtable); + wire_sync_write(REQ_FD, + take(towire_dual_open_dev_memleak_reply(NULL, + found_leak))); +} + +/* We were told to send a custommsg to the peer by `lightningd`. All the + * verification is done on the side of `lightningd` so we should be good to + * just forward it here. */ +static void dualopend_send_custommsg(struct state *state, const u8 *msg) +{ + sync_crypto_write(state->pps, take(msg)); +} +#endif + + static struct wally_psbt * fetch_psbt_changes(struct state *state, const struct wally_psbt *psbt) { @@ -1869,39 +1903,6 @@ static u8 *opener_start(struct state *state, u8 *msg) } -/* Memory leak detection is DEVELOPER-only because we go to great lengths to - * record the backtrace when allocations occur: without that, the leak - * detection tends to be useless for diagnosing where the leak came from, but - * it has significant overhead. */ -#if DEVELOPER -static void handle_dev_memleak(struct state *state, const u8 *msg) -{ - struct htable *memtable; - bool found_leak; - - /* Populate a hash table with all our allocations (except msg, which - * is in use right now). */ - memtable = memleak_find_allocations(tmpctx, msg, msg); - - /* Now delete state and things it has pointers to. */ - memleak_remove_region(memtable, state, tal_bytelen(state)); - - /* If there's anything left, dump it to logs, and return true. */ - found_leak = dump_memleak(memtable); - wire_sync_write(REQ_FD, - take(towire_dual_open_dev_memleak_reply(NULL, - found_leak))); -} - -/* We were told to send a custommsg to the peer by `lightningd`. All the - * verification is done on the side of `lightningd` so we should be good to - * just forward it here. */ -static void dualopend_send_custommsg(struct state *state, const u8 *msg) -{ - sync_crypto_write(state->pps, take(msg)); -} -#endif - /*~ If we see the gossip_fd readable, we read a whole message. Sure, we might * block, but we trust gossipd. */ static void handle_gossip_in(struct state *state)