mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user