Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
ccb7047291
  1. 4
      lightningd/bitcoind.c
  2. 5
      lightningd/chaintopology.c
  3. 11
      lightningd/jsonrpc.c

4
lightningd/bitcoind.c

@ -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);
}

5
lightningd/chaintopology.c

@ -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. */

11
lightningd/jsonrpc.c

@ -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));
}

Loading…
Cancel
Save