From debec7d6e95887786b81b2f3cdfada4cb302d40f Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 6 Jun 2023 10:06:04 -0500 Subject: [PATCH] tools: fix memory leaks in hsmtool Detected by ASan in test_hsmtool_generatehsm: ==58698==ERROR: LeakSanitizer: detected memory leaks Direct leak of 120 byte(s) in 1 object(s) allocated from: #0 0x4e6247 in malloc #1 0x7f078452d672 in getdelim SUMMARY: AddressSanitizer: 120 byte(s) leaked in 1 allocation(s). --- tools/hsmtool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/hsmtool.c b/tools/hsmtool.c index 447fdd253ebd..466a6847ee29 100644 --- a/tools/hsmtool.c +++ b/tools/hsmtool.c @@ -448,6 +448,7 @@ static void get_words(struct words **words) { if (errno == ERANGE || (errno != 0 && val == 0) || endptr == selected || val < 0 || val >= ARRAY_SIZE(languages)) errx(ERROR_USAGE, "Invalid language selection, select one from the list [0-6]."); + free(selected); bip39_get_wordlist(languages[val].abbr, words); } @@ -610,6 +611,8 @@ static int check_hsm(const char *hsm_secret_path) errx(ERROR_KEYDERIV, "resulting hsm_secret did not match"); printf("OK\n"); + + free(passphrase); return 0; }