@@ -301,7 +301,6 @@ static void hsmd_send_init_reply_failure(enum hsm_secret_error error_code, enum
301301static void create_hsm (int fd , const char * passphrase )
302302{
303303 u8 * hsm_secret_data ;
304- size_t hsm_secret_len ;
305304 int ret ;
306305 /* Always create a mnemonic-based hsm_secret */
307306 u8 entropy [BIP39_ENTROPY_LEN_128 ];
@@ -313,7 +312,6 @@ static void create_hsm(int fd, const char *passphrase)
313312 /* Generate random entropy for new mnemonic */
314313 randombytes_buf (entropy , sizeof (entropy ));
315314
316-
317315 /* Generate mnemonic from entropy */
318316 tal_wally_start ();
319317 ret = bip39_mnemonic_from_bytes (NULL , entropy , sizeof (entropy ), & mnemonic );
@@ -322,27 +320,26 @@ static void create_hsm(int fd, const char *passphrase)
322320 if (ret != WALLY_OK ) {
323321 unlink_noerr ("hsm_secret" );
324322 hsmd_send_init_reply_failure (HSM_SECRET_ERR_SEED_DERIVATION_FAILED , STATUS_FAIL_INTERNAL_ERROR ,
325- "Failed to generate mnemonic from entropy" );
323+ "Failed to generate mnemonic from entropy" );
326324 }
327325
328326 if (!mnemonic ) {
329327 unlink_noerr ("hsm_secret" );
330328 hsmd_send_init_reply_failure (HSM_SECRET_ERR_SEED_DERIVATION_FAILED , STATUS_FAIL_INTERNAL_ERROR ,
331- "Failed to get generated mnemonic" );
329+ "Failed to get generated mnemonic" );
332330 }
333331
334332 /* Derive seed hash from mnemonic + passphrase (or zero if no passphrase) */
335333 if (!derive_seed_hash (mnemonic , passphrase , & seed_hash )) {
336334 unlink_noerr ("hsm_secret" );
337335 hsmd_send_init_reply_failure (HSM_SECRET_ERR_SEED_DERIVATION_FAILED , STATUS_FAIL_INTERNAL_ERROR ,
338- "Failed to derive seed hash from mnemonic" );
336+ "Failed to derive seed hash from mnemonic" );
339337 }
340338
341339 /* Create hsm_secret format: seed_hash (32 bytes) + mnemonic */
342340 hsm_secret_data = tal_arr (tmpctx , u8 , 0 );
343341 towire_sha256 (& hsm_secret_data , & seed_hash );
344342 towire (& hsm_secret_data , mnemonic , strlen (mnemonic ));
345- hsm_secret_len = tal_count (hsm_secret_data );
346343
347344 /* Derive the actual secret from mnemonic + passphrase for our global hsm_secret */
348345 u8 bip32_seed [BIP39_SEED_LEN_512 ];
@@ -358,7 +355,7 @@ static void create_hsm(int fd, const char *passphrase)
358355 }
359356
360357 /* Write the hsm_secret data to file */
361- if (!write_all (fd , hsm_secret_data , hsm_secret_len )) {
358+ if (!write_all (fd , hsm_secret_data , tal_count ( hsm_secret_data ) )) {
362359 unlink_noerr ("hsm_secret" );
363360 status_failed (STATUS_FAIL_INTERNAL_ERROR ,
364361 "writing: %s" , strerror (errno ));
@@ -494,7 +491,7 @@ static struct io_plan *init_hsm(struct io_conn *conn,
494491 u32 minversion , maxversion ;
495492 struct tlv_hsmd_init_tlvs * tlvs ;
496493 const u32 our_minversion = 4 , our_maxversion = 6 ;
497- const char * hsm_passphrase = NULL ; /* Initialize to NULL */
494+ const char * hsm_passphrase ;
498495
499496 /* This must be lightningd. */
500497 assert (is_lightningd (c ));
@@ -531,6 +528,8 @@ static struct io_plan *init_hsm(struct io_conn *conn,
531528 * never sets that anymore), and we use the TLV instead. */
532529 if (tlvs -> hsm_passphrase )
533530 hsm_passphrase = tlvs -> hsm_passphrase ;
531+ else
532+ hsm_passphrase = NULL ;
534533
535534 if (!developer ) {
536535 assert (!dev_force_privkey );
@@ -637,6 +636,7 @@ static struct io_plan *handle_memleak(struct io_conn *conn,
637636
638637 memleak_ptr (memtable , dev_force_privkey );
639638 memleak_ptr (memtable , dev_force_bip32_seed );
639+
640640 found_leak = dump_memleak (memtable , memleak_status_broken , NULL );
641641 reply = towire_hsmd_dev_memleak_reply (NULL , found_leak );
642642 return req_reply (conn , c , take (reply ));
@@ -768,15 +768,16 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
768768 case WIRE_HSMD_CLIENT_HSMFD :
769769 return pass_client_hsmfd (conn , c , c -> msg_in );
770770
771- case WIRE_HSMD_DEV_MEMLEAK :
772- if (developer )
773- return handle_memleak (conn , c , c -> msg_in );
774- /* fall thru */
775-
776771 case WIRE_HSMD_DERIVE_BIP86_KEY :
777772 return handle_derive_bip86_key (conn , c , c -> msg_in );
778773 case WIRE_HSMD_CHECK_BIP86_PUBKEY :
779774 return handle_check_bip86_pubkey (conn , c , c -> msg_in );
775+
776+ case WIRE_HSMD_DEV_MEMLEAK :
777+ if (!developer )
778+ break ;
779+ return handle_memleak (conn , c , c -> msg_in );
780+
780781 case WIRE_HSMD_NEW_CHANNEL :
781782 case WIRE_HSMD_SETUP_CHANNEL :
782783 case WIRE_HSMD_CHECK_OUTPOINT :
0 commit comments