[PATCH 1/2] fs: fix error path in __canonicalize_path()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Report failure in resolving links to the caller and only clean up memory then.

Signed-off-by: Ulrich Ölmann <u.oelmann@xxxxxxxxxxxxxx>
---
 fs/fs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 5135112c8b81..7c818eca024f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -202,8 +202,11 @@ static char *__canonicalize_path(const char *_pathname, int level)
 			continue;
 
 		ret = readlink(outpath, link, PATH_MAX - 1);
-		if (ret < 0)
+		if (ret < 0) {
+			free(outpath);
+			outpath = ERR_PTR(ret);
 			goto out;
+		}
 
 		if (link[0] == '/') {
 			free(outpath);
@@ -218,14 +221,15 @@ static char *__canonicalize_path(const char *_pathname, int level)
 		if (IS_ERR(outpath))
 			goto out;
 	}
-out:
-	free(freep);
 
 	if (!*outpath) {
 		free(outpath);
 		outpath = xstrdup("/");
 	}
 
+out:
+	free(freep);
+
 	return outpath;
 }
 
-- 
2.16.3


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux