From c1f534a159ad97eaaea1cd61bcc54b1e9bcd620c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 25 Nov 2021 06:29:20 +1030 Subject: [PATCH] backtrace: avoid duplicate backtrace objects. This happened in my tal_dump(), and I couldn't see how we ended up with object having more than one "backtrace". Adding asserts that we never added a second backtrace didn't trigger. Finally I wondered if we were tal_steal() backtraces, and sure enough we do that blinding in one place: libwally wrapping. So fix that. Signed-off-by: Rusty Russell --- common/utils.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/utils.c b/common/utils.c index a9ed0f23c986..311de3e0a8e6 100644 --- a/common/utils.c +++ b/common/utils.c @@ -32,8 +32,16 @@ void tal_wally_end(const tal_t *parent) { tal_t *p; while ((p = tal_first(wally_tal_ctx)) != NULL) { - if (p != parent) + if (p != parent) { +#if DEVELOPER + /* Don't steal backtrace from wally_tal_ctx! */ + if (tal_name(p) && streq(tal_name(p), "backtrace")) { + tal_free(p); + continue; + } +#endif /* DEVELOPER */ tal_steal(parent, p); + } } wally_tal_ctx = tal_free(wally_tal_ctx); }