[lxc-devel] [go-lxc/v2] bug: Fix fd leak in go_lxc_clone

theopolis on Github lxc-bot at linuxcontainers.org
Thu Apr 4 02:39:41 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 500 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190403/114a8bfd/attachment.bin>
-------------- next part --------------
From a7c9a66be72b0468e7c75acb3116653c5955ac22 Mon Sep 17 00:00:00 2001
From: Teddy Reed <teddy at casualhacking.io>
Date: Wed, 3 Apr 2019 22:37:41 -0400
Subject: [PATCH] bug: Fix fd leak in go_lxc_clone

---
 lxc-binding.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lxc-binding.c b/lxc-binding.c
index 4c37b82..51d6a9a 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -195,7 +195,12 @@ bool go_lxc_save_config(struct lxc_container *c, const char *alt_file) {
 }
 
 bool go_lxc_clone(struct lxc_container *c, const char *newname, const char *lxcpath, int flags, const char *bdevtype) {
-	return c->clone(c, newname, lxcpath, flags, bdevtype, NULL, 0, NULL) != NULL;
+	struct lxc_container *c2 = c->clone(c, newname, lxcpath, flags, bdevtype, NULL, 0, NULL);
+	if (c2 == NULL) {
+		return false;
+	}
+	lxc_container_put(c2);
+	return true;
 }
 
 int go_lxc_console_getfd(struct lxc_container *c, int ttynum) {


More information about the lxc-devel mailing list