[lxc-devel] [PATCH] Free allocated memory on failure (v2)

Christian Brauner christianvanbrauner at gmail.com
Mon Sep 28 11:33:33 UTC 2015


Signed-off-by: Christian Brauner <christianvanbrauner at gmail.com>
---
 src/lxc/bdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index 21a64f7..846fd82 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -2461,12 +2461,15 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
 		// and needs to be on the same filesystem as upperdir,
 		// so it's OK for it to be empty.
 		work = malloc(lastslashidx + 7);
-		if (!work)
+		if (!work) {
+			free(delta);
 			return -1;
+		}
 		strncpy(work, new->dest, lastslashidx+1);
 		strcpy(work+lastslashidx, "olwork");
 		if (mkdir(work, 0755) < 0) {
 			SYSERROR("error: mkdir %s", work);
+			free(delta);
 			free(work);
 			return -1;
 		}
-- 
2.5.3



More information about the lxc-devel mailing list