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 <norep@anthropic.com>
This commit is contained in:
shivanayak
2026-03-11 15:07:00 +05:30
committed by GitHub
parent 47c2233026
commit 2bc54b40f7

View File

@@ -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;
}