libplugin: mark the cmd notleak() whenever command_still_pending() called.

This is what we do in lightningd, which makes memleak much more forgiving:
you can hang temporaries off cmd without getting reports of leaks (also
when send_outreq called).

We remove all the notleak() calls in plugins which worked around this!
And avoid multiple notleak labels, since both send_outreq() and
command_still_pending() can be called multiple times.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-09-16 12:45:03 +09:30
parent 701dd3dcef
commit 5b58eda748
8 changed files with 19 additions and 37 deletions

View File

@@ -680,13 +680,12 @@ static struct command_result *json_commando(struct command *cmd,
tal_append_fmt(&json, ",\"rune\":\"%s\"", rune);
tal_append_fmt(&json, "}");
/* This is not a leak, but we don't keep a pointer. */
outgoing = notleak(tal(cmd, struct outgoing));
outgoing = tal(cmd, struct outgoing);
outgoing->peer = *peer;
outgoing->msg_off = 0;
/* 65000 per message gives sufficient headroom. */
jsonlen = tal_bytelen(json)-1;
outgoing->msgs = notleak(tal_arr(cmd, u8 *, (jsonlen + 64999) / 65000));
outgoing->msgs = tal_arr(cmd, u8 *, (jsonlen + 64999) / 65000);
for (size_t i = 0; i < tal_count(outgoing->msgs); i++) {
u8 *cmd_msg = tal_arr(outgoing, u8, 0);
bool terminal = (i == tal_count(outgoing->msgs) - 1);
@@ -705,12 +704,6 @@ static struct command_result *json_commando(struct command *cmd,
outgoing->msgs[i] = cmd_msg;
}
/* Keep memleak code happy! */
tal_free(peer);
tal_free(method);
tal_free(cparams);
tal_free(rune);
return send_more_cmd(cmd, NULL, NULL, outgoing);
}