@@ -277,16 +277,13 @@ static void negotiation_aborted(struct state *state, const char *why)
277277 memset (& state -> channel_id , 0 , sizeof (state -> channel_id ));
278278 state -> channel = tal_free (state -> channel );
279279 state -> changeset = tal_free (state -> changeset );
280- if (state -> psbt )
281- tal_free (state -> psbt );
282280
283281 for (size_t i = 0 ; i < NUM_TX_MSGS ; i ++ )
284282 state -> tx_msg_count [i ] = 0 ;
285283}
286284
287- /*~ For negotiation failures: we tell them the parameter we didn't like. */
288- static void negotiation_failed (struct state * state ,
289- const char * fmt , ...)
285+ static void open_error (struct state * state ,
286+ const char * fmt , ...)
290287{
291288 va_list ap ;
292289 const char * errmsg ;
@@ -297,12 +294,27 @@ static void negotiation_failed(struct state *state,
297294 va_end (ap );
298295
299296 msg = towire_errorfmt (NULL , & state -> channel_id ,
300- "You gave bad parameters: %s" , errmsg );
297+ "%s" , errmsg );
301298 sync_crypto_write (state -> pps , take (msg ));
302299
303300 negotiation_aborted (state , errmsg );
304301}
305302
303+
304+ /*~ For negotiation failures: we tell them the parameter we didn't like. */
305+ static void negotiation_failed (struct state * state ,
306+ const char * fmt , ...)
307+ {
308+ va_list ap ;
309+ const char * errmsg ;
310+
311+ va_start (ap , fmt );
312+ errmsg = tal_vfmt (tmpctx , fmt , ap );
313+ va_end (ap );
314+
315+ open_error (state , "You gave bad parameters: %s" , errmsg );
316+ }
317+
306318static void billboard_update (struct state * state )
307319{
308320 const char * update = billboard_message (tmpctx , state -> funding_locked ,
@@ -885,9 +897,9 @@ fetch_psbt_changes(struct state *state, const struct wally_psbt *psbt)
885897 wire_sync_write (REQ_FD , take (msg ));
886898 msg = wire_sync_read (tmpctx , REQ_FD );
887899
888- if (fromwire_dualopend_fail (msg , msg , & err ))
889- status_failed ( STATUS_FAIL_MASTER_IO , "%s" , err );
890- else if (fromwire_dualopend_psbt_updated (state , msg , & updated_psbt )) {
900+ if (fromwire_dualopend_fail (msg , msg , & err )) {
901+ open_error ( state , "%s" , err );
902+ } else if (fromwire_dualopend_psbt_updated (state , msg , & updated_psbt )) {
891903 return updated_psbt ;
892904#if DEVELOPER
893905 } else if (fromwire_dualopend_dev_memleak (msg )) {
@@ -1507,7 +1519,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
15071519 if (!fromwire_dualopend_fail (msg , msg , & err_reason ))
15081520 master_badmsg (msg_type , msg );
15091521
1510- negotiation_failed (state , "%s" , err_reason );
1522+ open_error (state , "%s" , err_reason );
15111523 return ;
15121524 }
15131525
@@ -1927,7 +1939,7 @@ static void opener_start(struct state *state, u8 *msg)
19271939 if (!msg )
19281940 return ;
19291941
1930- a_tlv = tlv_accept_tlvs_new (state );
1942+ a_tlv = notleak ( tlv_accept_tlvs_new (state ) );
19311943 if (!fromwire_accept_channel2 (msg , & cid ,
19321944 & state -> accepter_funding ,
19331945 & state -> feerate_per_kw_funding ,
@@ -2017,9 +2029,11 @@ static void opener_start(struct state *state, u8 *msg)
20172029 * - MUST send at least one `tx_add_output`, the channel
20182030 * funding output.
20192031 */
2020- wscript = bitcoin_redeem_2of2 (state ,
2021- & state -> our_funding_pubkey ,
2022- & state -> their_funding_pubkey );
2032+ /* If fails before returning from `send_next`, this will
2033+ * be marked as a memleak */
2034+ wscript = notleak (bitcoin_redeem_2of2 (state ,
2035+ & state -> our_funding_pubkey ,
2036+ & state -> their_funding_pubkey ));
20232037 funding_out = psbt_append_output (state -> psbt ,
20242038 scriptpubkey_p2wsh (tmpctx ,
20252039 wscript ),
@@ -2052,7 +2066,7 @@ static void opener_start(struct state *state, u8 *msg)
20522066
20532067 /* Send our first message, we're opener we initiate here */
20542068 if (!send_next (state , & state -> psbt ))
2055- negotiation_failed (state , "Peer error, no updates to send" );
2069+ open_error (state , "Peer error, no updates to send" );
20562070
20572071 /* Figure out what the funding transaction looks like! */
20582072 if (!run_tx_interactive (state , & state -> psbt , TX_INITIATOR ))
0 commit comments