From e8de77c5c38b18981581c93b86961c2a4dedf1af Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 1 Jul 2022 16:55:33 +0930 Subject: [PATCH] ccan/rune: fix take() logic which caused memory leaks. You have to tal_steal() if you want to keep it! Signed-off-by: Rusty Russell --- ccan/rune/rune.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ccan/rune/rune.c b/ccan/rune/rune.c index 36eaab92..19d55c54 100644 --- a/ccan/rune/rune.c +++ b/ccan/rune/rune.c @@ -66,7 +66,7 @@ struct rune *rune_dup(const tal_t *ctx, const struct rune *rune TAKES) struct rune *dup; if (taken(rune)) - return (struct rune *)rune; + return tal_steal(ctx, (struct rune *)rune); dup = tal_dup(ctx, struct rune, rune); dup->restrs = tal_arr(dup, struct rune_restr *, tal_count(rune->restrs)); @@ -86,7 +86,7 @@ struct rune *rune_derive_start(const tal_t *ctx, /* If they provide a unique_id, it goes first. */ if (unique_id) { if (taken(unique_id)) - rune->unique_id = unique_id; + rune->unique_id = tal_steal(rune, unique_id); else rune->unique_id = tal_strdup(rune, unique_id); @@ -117,7 +117,7 @@ struct rune_altern *rune_altern_dup(const tal_t *ctx, struct rune_altern *dup; if (taken(altern)) - return (struct rune_altern *)altern;; + return tal_steal(ctx, (struct rune_altern *)altern); dup = tal(ctx, struct rune_altern); dup->condition = altern->condition; dup->fieldname = tal_strdup(dup, altern->fieldname); @@ -132,7 +132,7 @@ struct rune_restr *rune_restr_dup(const tal_t *ctx, size_t num_altern; if (taken(restr)) - return (struct rune_restr *)restr; + return tal_steal(ctx, (struct rune_restr *)restr); num_altern = tal_count(restr->alterns); dup = tal(ctx, struct rune_restr); -- 2.39.2