@@ -113,7 +113,7 @@ static void destroy_peer(struct peer *peer)
113113static struct peer * new_peer (struct daemon * daemon ,
114114 const struct node_id * id ,
115115 const struct crypto_state * cs ,
116- const u8 * their_features ,
116+ const u8 * their_features TAKES ,
117117 enum is_websocket is_websocket ,
118118 struct timemono connect_starttime ,
119119 struct io_conn * conn STEALS ,
@@ -154,6 +154,7 @@ static struct peer *new_peer(struct daemon *daemon,
154154 peer -> onionmsg_incoming_tokens = ONION_MSG_TOKENS_MAX ;
155155 peer -> onionmsg_last_incoming = time_mono ();
156156 peer -> onionmsg_limit_warned = false;
157+ peer -> their_features = tal_dup_talarr (peer , u8 , their_features );
157158
158159 peer -> to_peer = conn ;
159160
@@ -320,10 +321,6 @@ struct io_plan *peer_connected(struct io_conn *conn,
320321 destroy_peer_immediately (oldpeer );
321322 }
322323
323- /* We promised we'd take it by marking it TAKEN above; prepare to free it. */
324- if (taken (their_features ))
325- tal_steal (tmpctx , their_features );
326-
327324 /* BOLT #1:
328325 *
329326 * The receiving node:
@@ -336,6 +333,9 @@ struct io_plan *peer_connected(struct io_conn *conn,
336333 unsup = features_unsupported (daemon -> our_features , their_features ,
337334 INIT_FEATURE );
338335 if (unsup != -1 ) {
336+ if (taken (their_features ))
337+ tal_free (their_features );
338+
339339 /* We were going to send a reconnect message, but not now! */
340340 if (oldpeer )
341341 send_disconnected (daemon , id , prev_connectd_counter ,
@@ -348,6 +348,9 @@ struct io_plan *peer_connected(struct io_conn *conn,
348348 }
349349
350350 if (!feature_check_depends (their_features , & depender , & missing )) {
351+ if (taken (their_features ))
352+ tal_free (their_features );
353+
351354 /* We were going to send a reconnect message, but not now! */
352355 if (oldpeer )
353356 send_disconnected (daemon , id , prev_connectd_counter ,
@@ -407,19 +410,19 @@ struct io_plan *peer_connected(struct io_conn *conn,
407410
408411 /* Tell gossipd it can ask query this new peer for gossip */
409412 option_gossip_queries = feature_negotiated (daemon -> our_features ,
410- their_features ,
413+ peer -> their_features ,
411414 OPT_GOSSIP_QUERIES );
412415
413416 /* Get ready for streaming gossip from the store */
414- setup_peer_gossip_store (peer , daemon -> our_features , their_features );
417+ setup_peer_gossip_store (peer , daemon -> our_features , peer -> their_features );
415418
416419 /* Create message to tell master peer has connected/reconnected. */
417420 if (oldpeer ) {
418421 msg = towire_connectd_peer_reconnected (NULL , id ,
419422 prev_connectd_counter ,
420423 peer -> counter ,
421424 addr , remote_addr ,
422- incoming , their_features ,
425+ incoming , peer -> their_features ,
423426 time_to_nsec (timemono_since (prev_connect_start )));
424427 } else {
425428 /* Tell gossipd about new peer */
@@ -428,7 +431,7 @@ struct io_plan *peer_connected(struct io_conn *conn,
428431
429432 msg = towire_connectd_peer_connected (NULL , id , peer -> counter ,
430433 addr , remote_addr ,
431- incoming , their_features ,
434+ incoming , peer -> their_features ,
432435 connect_reason ,
433436 connect_time_nsec );
434437 }
0 commit comments