[CRIU] [PATCH] libcriu: criu_init_opts: don't leak on rpc and opts

Ruslan Kuprieiev kupruser at gmail.com
Tue Jul 21 03:27:39 PDT 2015


Reported-by: Andrew Vagin <avagin at gmail.com>
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 lib/criu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/criu.c b/lib/criu.c
index 8008981..e137be7 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -76,8 +76,13 @@ int criu_local_init_opts(criu_opts **o)
 
 	opts = *o;
 
-	if (opts && opts->rpc)
-		criu_opts__free_unpacked(opts->rpc, NULL);
+	if (opts) {
+		if (opts->rpc)
+			criu_opts__free_unpacked(opts->rpc, NULL);
+
+		free(opts);
+		opts = NULL;
+	}
 
 	rpc = malloc(sizeof(CriuOpts));
 	if (rpc == NULL) {
@@ -90,6 +95,7 @@ int criu_local_init_opts(criu_opts **o)
 	opts = malloc(sizeof(criu_opts));
 	if (opts == NULL) {
 		perror("Can't allocate memory for criu opts");
+		criu_opts__free_unpacked(rpc, NULL);
 		return -1;
 	}
 
-- 
2.1.0



More information about the CRIU mailing list