[PATCH 4/9] util: use _cleanup_free_ on path_make_absolute_cwd()

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

 



---
 libkmod/libkmod-util.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c
index d686250..837f417 100644
--- a/libkmod/libkmod-util.c
+++ b/libkmod/libkmod-util.c
@@ -283,15 +283,15 @@ bool path_is_absolute(const char *p)
 
 char *path_make_absolute_cwd(const char *p)
 {
-	char *cwd, *r;
-	size_t plen;
-	size_t cwdlen;
+	_cleanup_free_ char *cwd = NULL;
+	size_t plen, cwdlen;
+	char *r;
 
 	if (path_is_absolute(p))
 		return strdup(p);
 
 	cwd = get_current_dir_name();
-	if (cwd == NULL)
+	if (!cwd)
 		return NULL;
 
 	plen = strlen(p);
@@ -299,11 +299,10 @@ char *path_make_absolute_cwd(const char *p)
 
 	/* cwd + '/' + p + '\0' */
 	r = realloc(cwd, cwdlen + 1 + plen + 1);
-	if (r == NULL) {
-		free(cwd);
+	if (r == NULL)
 		return NULL;
-	}
 
+	cwd = NULL;
 	r[cwdlen] = '/';
 	memcpy(&r[cwdlen + 1], p, plen + 1);
 
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux