From 5efcbae259826a184dc962822a4e060a21f5175c Mon Sep 17 00:00:00 2001 From: David Tardon Date: Thu, 6 Nov 2025 13:54:35 +0100 Subject: [PATCH 1/2] homectl: fix memory leak # valgrind --leak-check=full homectl create waldo --real-name=Waldo --disk-size=200M --setopt=FOO=bar Before: ==25155== HEAP SUMMARY: ==25155== in use at exit: 12,879 bytes in 39 blocks ==25155== total heap usage: 90 allocs, 51 frees, 53,964 bytes allocated ==25155== ==25155== 8 bytes in 1 blocks are definitely lost in loss record 4 of 38 ==25155== at 0x4845866: malloc (vg_replace_malloc.c:446) ==25155== by 0x547FC2E: strdup (strdup.c:42) ==25155== by 0x4B2647C: strv_env_replace_strdup_passthrough (env-util.c:435) ==25155== by 0x42D547: parse_argv (homectl.c:3909) ==25155== by 0x43999C: run (homectl.c:5606) ==25155== by 0x4399F5: main (homectl.c:5613) ==25155== ==25155== LEAK SUMMARY: ==25155== definitely lost: 8 bytes in 1 blocks After: ==25224== HEAP SUMMARY: ==25224== in use at exit: 12,871 bytes in 38 blocks ==25224== total heap usage: 90 allocs, 52 frees, 53,964 bytes allocated ==25224== ==25224== LEAK SUMMARY: ==25224== definitely lost: 0 bytes in 0 blocks Follow-up-for: aaf057c4bbc6055040d7d2c1ec3655ff89249ebd --- src/home/homectl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/home/homectl.c b/src/home/homectl.c index a73d94744a..09144fb909 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -3887,7 +3887,7 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_SETENV: { - _cleanup_free_ char **l = NULL; + _cleanup_strv_free_ char **l = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *ne = NULL; sd_json_variant *e; From 399c9f847e222d6e62c553ac9ea2bebeb7c1be7f Mon Sep 17 00:00:00 2001 From: David Tardon Date: Thu, 6 Nov 2025 14:04:32 +0100 Subject: [PATCH 2/2] ask-password-api: return if read_credential() failed The current code causes assertion in strv_parse_nulstr() if read_credential() results in an error different from ENXIO or ENOENT (strace shows I'm getting EACCES): # homectl create waldo --real-name=Waldo --disk-size=200M Before: Assertion 's || l <= 0' failed at src/basic/nulstr-util.c:32, function strv_parse_nulstr_full(). Aborting. After: Failed to acquire password: Permission denied Follow-up-for: 8806bb4bc7fa15d6ca46e81b8d535730209a3b66 --- src/shared/ask-password-api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index dd6b8abc65..b8602eee78 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -1133,6 +1133,8 @@ static int ask_password_credential(const AskPasswordRequest *req, AskPasswordFla r = read_credential(req->credential, (void**) &buffer, &size); if (IN_SET(r, -ENXIO, -ENOENT)) /* No credentials passed or this credential not defined? */ return -ENOKEY; + if (r < 0) + return r; l = strv_parse_nulstr(buffer, size); if (!l)