* [PATCH] tools/vm-set-persist.c: fix "memory leak"
@ 2026-05-10 16:55 Alyssa Ross
2026-05-18 7:10 ` Alyssa Ross
0 siblings, 1 reply; 2+ messages in thread
From: Alyssa Ross @ 2026-05-10 16:55 UTC (permalink / raw)
To: devel
Newer versions of clang-tidy complain about the "memory leak" from
strdup. This is not a problem because this is not a long lived
program nor a large allocation, but I think it's probably better to
appease clang-tidy than to override it.
Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
tools/vm-set-persist.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/vm-set-persist.c b/tools/vm-set-persist.c
index ac759504..8f714b38 100644
--- a/tools/vm-set-persist.c
+++ b/tools/vm-set-persist.c
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2025 Alyssa Ross <hi@alyssa.is>
+// SPDX-FileCopyrightText: 2025-2026 Alyssa Ross <hi@alyssa.is>
// SPDX-License-Identifier: EUPL-1.2+
#include <err.h>
@@ -142,11 +142,12 @@ static void do_rename(int mnt, const char dir_name[static 1],
int main(int argc, char *argv[])
{
- int mnt;
+ int mnt, r;
mode_t mode;
uint64_t mnt_id;
char *disk_path, *dir_name, *old_name, *new_name,
- mnt_root[MNT_ROOT_MAX_LEN], source[SOURCE_MAX_LEN];
+ mnt_root[MNT_ROOT_MAX_LEN], mnt_root_copy[MNT_ROOT_MAX_LEN],
+ source[SOURCE_MAX_LEN];
if (argc != 3) {
fprintf(stderr, "Usage: vm-set-persist ID INSTANCE\n");
@@ -168,10 +169,13 @@ int main(int argc, char *argv[])
do_statx(disk_path, &mode, &mnt_id);
do_statmount(mnt_id, mnt_root, source);
- if (!(dir_name = strdup(mnt_root)))
- err(EXIT_FAILURE, "strdup");
- dir_name = dirname(dir_name);
- old_name = basename(mnt_root);
+ r = snprintf(mnt_root_copy, sizeof mnt_root_copy, "%s", mnt_root);
+ if (r == -1)
+ err(EXIT_FAILURE, "snprintf");
+ if ((size_t)r >= sizeof mnt_root_copy)
+ errx(EXIT_FAILURE, "mnt_root longer than mnt_root_copy");
+ dir_name = dirname(mnt_root);
+ old_name = basename(mnt_root_copy);
mnt = do_mount(source);
base-commit: 508851e5d884bc3f2906947dcd43b055dc0465f4
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools/vm-set-persist.c: fix "memory leak"
2026-05-10 16:55 [PATCH] tools/vm-set-persist.c: fix "memory leak" Alyssa Ross
@ 2026-05-18 7:10 ` Alyssa Ross
0 siblings, 0 replies; 2+ messages in thread
From: Alyssa Ross @ 2026-05-18 7:10 UTC (permalink / raw)
To: Alyssa Ross, devel
This patch has been committed as c9dc121bc68696cf5c7e9045e7af1ba546ea9bfd,
which can be viewed online at
https://spectrum-os.org/git/spectrum/commit/?id=c9dc121bc68696cf5c7e9045e7af1ba546ea9bfd.
This is an automated message. Send comments/questions/requests to:
Alyssa Ross <hi@alyssa.is>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-18 7:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-10 16:55 [PATCH] tools/vm-set-persist.c: fix "memory leak" Alyssa Ross
2026-05-18 7:10 ` Alyssa Ross
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).