Skip to content

Commit 9af01b0

Browse files
committed
pytest: fix hsmtool which reports leak under address sanitizer.
Couldn't figure out why hsmtool.proc.wait(WAIT_TIMEOUT) returns 1? hsmtool doesn't ever seem to exit status 1! Signed-off-by: Rusty Russell <[email protected]>
1 parent 0741d4d commit 9af01b0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tests/test_wallet.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,12 @@ def test_hsmtool_generatehsm(node_factory):
13381338
"cake have wedding\n".encode("utf-8"))
13391339
hsmtool.wait_for_log(r"Enter your passphrase:")
13401340
write_all(master_fd, "This is actually not a passphrase\n".encode("utf-8"))
1341-
assert hsmtool.proc.wait(WAIT_TIMEOUT) == 0
1341+
if hsmtool.proc.wait(WAIT_TIMEOUT) != 0:
1342+
hsmtool.logs_catchup()
1343+
print("hsmtool failure! Logs:")
1344+
for l in hsmtool.logs:
1345+
print(' ' + l)
1346+
assert False
13421347
hsmtool.is_in_log(r"New hsm_secret file created")
13431348

13441349
# Check should pass.

tools/hsmtool.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static char *read_mnemonic(void) {
530530

531531
static int generate_hsm(const char *hsm_secret_path,
532532
const char *lang_id,
533-
const char *mnemonic,
533+
char *mnemonic,
534534
char *passphrase)
535535
{
536536
const char *err;
@@ -584,6 +584,7 @@ static int generate_hsm(const char *hsm_secret_path,
584584
printf("New hsm_secret file created at %s\n", hsm_secret_path);
585585
printf("Use the `encrypt` command to encrypt the BIP32 seed if needed\n");
586586

587+
free(mnemonic);
587588
free(passphrase);
588589
return 0;
589590
}
@@ -685,6 +686,7 @@ static int check_hsm(const char *hsm_secret_path)
685686

686687
printf("OK\n");
687688

689+
free(mnemonic);
688690
free(passphrase);
689691
return 0;
690692
}
@@ -810,8 +812,8 @@ int main(int argc, char *argv[])
810812
if (lang_id && !check_lang(lang_id))
811813
show_usage(argv[0]);
812814

813-
word_list = (argc > 4 ? argv[4] : NULL);
814-
/* generate_hsm expects to free this, so use strdup */
815+
/* generate_hsm expects to free these, so use strdup */
816+
word_list = (argc > 4 ? strdup(argv[4]) : NULL);
815817
passphrase = (argc > 5 ? strdup(argv[5]) : NULL);
816818

817819
return generate_hsm(hsm_secret_path, lang_id, word_list, passphrase);

0 commit comments

Comments
 (0)