lightningd: add notleak annotations.

We have things which we don't keep a pointer to, but aren't leaks.
Some are simply eternal (eg. listening sockets), others cases are
io_conn tied to the lifetime of an fd, and timers which expire.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-12-15 20:52:57 +10:30 committed by Christian Decker
parent 6c951bf7e0
commit ccb7047291
3 changed files with 14 additions and 6 deletions

View File

@ -16,6 +16,7 @@
#include <ccan/tal/str/str.h>
#include <ccan/tal/tal.h>
#include <common/json.h>
#include <common/memleak.h>
#include <common/utils.h>
#include <errno.h>
#include <inttypes.h>
@ -176,7 +177,8 @@ static void next_bcli(struct bitcoind *bitcoind)
fatal("%s exec failed: %s", bcli->args[0], strerror(errno));
bitcoind->req_running = true;
conn = io_new_conn(bitcoind, bcli->fd, output_init, bcli);
/* This lifetime is attached to bitcoind command fd */
conn = notleak(io_new_conn(bitcoind, bcli->fd, output_init, bcli));
io_set_finish(conn, bcli_finished, bcli);
}

View File

@ -25,8 +25,9 @@ static void next_topology_timer(struct chain_topology *topo)
topo->startup = false;
io_break(topo);
}
new_reltimer(topo->timers, topo, topo->poll_time,
start_poll_chaintip, topo);
/* This takes care of its own lifetime. */
notleak(new_reltimer(topo->timers, topo, topo->poll_time,
start_poll_chaintip, topo));
}
/* FIXME: Remove tx from block when peer done. */

View File

@ -7,6 +7,7 @@
#include <ccan/str/hex/hex.h>
#include <ccan/tal/str/str.h>
#include <common/json.h>
#include <common/memleak.h>
#include <common/version.h>
#include <common/wireaddr.h>
#include <errno.h>
@ -633,7 +634,9 @@ static struct io_plan *incoming_jcon_connected(struct io_conn *conn,
struct lightningd *ld)
{
log_info(ld->log, "Connected json input");
return jcon_connected(conn, ld);
/* Lifetime of JSON conn is limited to fd connect time. */
return jcon_connected(notleak(conn), ld);
}
void setup_jsonrpc(struct lightningd *ld, const char *rpc_filename)
@ -648,7 +651,8 @@ void setup_jsonrpc(struct lightningd *ld, const char *rpc_filename)
fd = open(rpc_filename, O_RDWR);
if (fd == -1)
err(1, "Opening %s", rpc_filename);
io_new_conn(ld, fd, jcon_connected, ld);
/* Technically this is a leak, but there's only one */
notleak(io_new_conn(ld, fd, jcon_connected, ld));
return;
}
@ -673,5 +677,6 @@ void setup_jsonrpc(struct lightningd *ld, const char *rpc_filename)
err(1, "Listening on '%s'", rpc_filename);
log_debug(ld->log, "Listening on '%s'", rpc_filename);
io_new_listener(ld, fd, incoming_jcon_connected, ld);
/* Technically this is a leak, but there's only one */
notleak(io_new_listener(ld, fd, incoming_jcon_connected, ld));
}