Skip to content

Commit 8d69f94

Browse files
committed
peer_control: Fix a use-after-free bug.
1 parent 234d67d commit 8d69f94

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightningd/peer_control.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ void peer_sent_nongossip(struct lightningd *ld,
458458
}
459459

460460
/* Weird request. */
461-
error = towire_errorfmt(ld, channel_id,
461+
/* Allocate off in_msg, which should get freed by the
462+
* caller. */
463+
error = towire_errorfmt(in_msg, channel_id,
462464
"Unexpected message %i for peer",
463465
fromwire_peektype(in_msg));
464466

@@ -469,7 +471,8 @@ void peer_sent_nongossip(struct lightningd *ld,
469471
subd_send_msg(ld->gossip, take(msg));
470472
subd_send_fd(ld->gossip, peer_fd);
471473
subd_send_fd(ld->gossip, gossip_fd);
472-
tal_free(error);
474+
/* Either error is allocated off in_msg, or error is owned by
475+
* the channel. Either way we have no need to free error here. */
473476
}
474477

475478
static enum watch_result funding_announce_cb(struct channel *channel,

0 commit comments

Comments
 (0)