From 2bc54b40f7fc452b285c62f5b82e9e054ad91fd9 Mon Sep 17 00:00:00 2001 From: shivanayak Date: Wed, 11 Mar 2026 15:07:00 +0530 Subject: [PATCH] lib: fix realpath memory leak on error paths in set_abs_path (#317) When realpath() succeeds but subsequent operations fail, the allocated path is leaked. Add free(ret) before returning -1 on both error paths. Co-authored-by: Claude --- lib/tmpdirs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tmpdirs.c b/lib/tmpdirs.c index 22b8f54b0..a1494f9df 100644 --- a/lib/tmpdirs.c +++ b/lib/tmpdirs.c @@ -71,12 +71,14 @@ set_abs_path (guestfs_h *g, const char *ctxstr, if (stat (ret, &statbuf) == -1) { perrorf (g, "%s: %s: %s: stat", _("setting temporary directory"), ctxstr, tmpdir); + free (ret); return -1; } if (!S_ISDIR (statbuf.st_mode)) { error (g, _("%s: %s: ā€˜%s’ is not a directory"), _("setting temporary directory"), ctxstr, tmpdir); + free (ret); return -1; }