[sheepdog] [PATCH v2] dog/farm/slice: fix memory leak in dog cluster snapshot load command

Ruoyu liangry at ucweb.com
Wed Apr 23 06:08:30 CEST 2014


In normal branch, we should free(file->slices) directly.
In error branch, we should check it first in case of slices not
allocated.

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 dog/farm/slice.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/dog/farm/slice.c b/dog/farm/slice.c
index 77db771..490a982 100644
--- a/dog/farm/slice.c
+++ b/dog/farm/slice.c
@@ -102,10 +102,15 @@ void *slice_read(const unsigned char *sha1, size_t *outsize)
 
 	object = xmalloc(*outsize);
 	strbuf_copyout(&buf, object, *outsize);
+	free(file->slices);
 	free(file);
 	strbuf_release(&buf);
 	return object;
 err:
+	if (file->slices) {
+		free(file->slices);
+		file->slices = NULL;
+	}
 	free(file);
 	strbuf_release(&buf);
 	return NULL;
-- 
1.8.3.2





More information about the sheepdog mailing list