Browse Source

htlc_out: initialize hout->key.id, in case we destroy it before setting.

We set hout->key.id when channeld tells us what it is, but if channeld
dies before that we free the hout, and our destructor logs it:

Valgrind error file: valgrind-errors.20312
==20312== Use of uninitialised value of size 8
==20312==    at 0x53ABC9B: _itoa_word (_itoa.c:179)
==20312==    by 0x53B041F: vfprintf (vfprintf.c:1642)
==20312==    by 0x53B17D5: buffered_vfprintf (vfprintf.c:2330)
==20312==    by 0x53AEAA5: vfprintf (vfprintf.c:1301)
==20312==    by 0x53B7D63: fprintf (fprintf.c:32)
==20312==    by 0x128BAC: hout_subd_died (peer_htlcs.c:316)
==20312==    by 0x16D8E0: notify (tal.c:240)
==20312==    by 0x16DD95: del_tree (tal.c:400)
==20312==    by 0x16DDE7: del_tree (tal.c:410)
==20312==    by 0x16DDE7: del_tree (tal.c:410)
==20312==    by 0x16E1B4: tal_free (tal.c:509)
==20312==    by 0x162B5C: io_close (io.c:443)
==20312==    by 0x12D563: sd_msg_read (subd.c:508)
==20312==    by 0x161EA5: next_plan (io.c:59)
==20312==    by 0x1629A2: do_plan (io.c:387)
==20312==    by 0x1629E0: io_ready (io.c:397)
==20312==    by 0x164319: io_loop (poll.c:305)
==20312==    by 0x118E21: main (lightningd.c:334)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
90a5ba043c
  1. 1
      lightningd/htlc_end.c
  2. 2
      lightningd/htlc_end.h
  3. 3
      lightningd/peer_htlcs.c

1
lightningd/htlc_end.c

@ -150,6 +150,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
hout->dbid = 0;
hout->key.peer = peer;
hout->key.id = HTLC_INVALID_ID;
hout->msatoshi = msatoshi;
hout->cltv_expiry = cltv_expiry;
hout->payment_hash = *payment_hash;

2
lightningd/htlc_end.h

@ -13,6 +13,8 @@ struct htlc_key {
u64 id;
};
#define HTLC_INVALID_ID (-1ULL)
/* Incoming HTLC */
struct htlc_in {
/* The database primary key for this htlc. Must be 0 until it

3
lightningd/peer_htlcs.c

@ -352,7 +352,8 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds,
return;
}
if (find_htlc_out(&subd->ld->htlcs_out, hout->key.peer, hout->key.id)) {
if (find_htlc_out(&subd->ld->htlcs_out, hout->key.peer, hout->key.id)
|| hout->key.id == HTLC_INVALID_ID) {
peer_internal_error(subd->peer,
"Bad offer_htlc_reply HTLC id %"PRIu64
" is a duplicate",

Loading…
Cancel
Save