[lxc-devel] [go-lxc/v2] lxc-binding: bugfixes

brauner on Github lxc-bot at linuxcontainers.org
Thu Sep 20 08:19:24 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 366 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180920/090ad981/attachment.bin>
-------------- next part --------------
From 7baaea306ce32746d535eb5eded138f0403dfc67 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 20 Sep 2018 10:16:06 +0200
Subject: [PATCH 1/2] lxc-binding: free memory on error

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc-binding.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lxc-binding.c b/lxc-binding.c
index 7998271..e2a0572 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -101,12 +101,12 @@ char* go_lxc_get_config_item(struct lxc_container *c, const char *key) {
 
 again:
 	value = (char*)malloc(sizeof(char)*len + 1);
-
 	if (value == NULL) {
 		goto again;
 	}
 
 	if (c->get_config_item(c, key, value, len + 1) != len) {
+		free(value);
 		return NULL;
 	}
 	return value;
@@ -144,6 +144,7 @@ char* go_lxc_get_keys(struct lxc_container *c, const char *key) {
 	}
 
 	if (c->get_keys(c, key, value, len + 1) != len) {
+		free(value);
 		return NULL;
 	}
 	return value;
@@ -165,6 +166,7 @@ char* go_lxc_get_cgroup_item(struct lxc_container *c, const char *key) {
 	}
 
 	if (c->get_cgroup_item(c, key, value, len + 1) != len) {
+		free(value);
 		return NULL;
 	}
 	return value;

From b386be80e6c7dddb65eb9512d4528e05210d15ed Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 20 Sep 2018 10:17:12 +0200
Subject: [PATCH 2/2] lxc-binding: coding-style fixes

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc-binding.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/lxc-binding.c b/lxc-binding.c
index e2a0572..8b4ce08 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -91,24 +91,24 @@ bool go_lxc_wait(struct lxc_container *c, const char *state, int timeout) {
 	return c->wait(c, state, timeout);
 }
 
-char* go_lxc_get_config_item(struct lxc_container *c, const char *key) {
+char *go_lxc_get_config_item(struct lxc_container *c, const char *key)
+{
 	char *value = NULL;
 
 	int len = c->get_config_item(c, key, NULL, 0);
-	if (len <= 0) {
+	if (len <= 0)
 		return NULL;
-	}
 
 again:
-	value = (char*)malloc(sizeof(char)*len + 1);
-	if (value == NULL) {
+	value = (char *)malloc(sizeof(char) * len + 1);
+	if (value == NULL)
 		goto again;
-	}
 
 	if (c->get_config_item(c, key, value, len + 1) != len) {
 		free(value);
 		return NULL;
 	}
+
 	return value;
 }
 
@@ -128,47 +128,45 @@ char* go_lxc_get_running_config_item(struct lxc_container *c, const char *key) {
 	return c->get_running_config_item(c, key);
 }
 
-char* go_lxc_get_keys(struct lxc_container *c, const char *key) {
+char *go_lxc_get_keys(struct lxc_container *c, const char *key)
+{
 	char *value = NULL;
 
 	int len = c->get_keys(c, key, NULL, 0);
-	if (len <= 0) {
+	if (len <= 0)
 		return NULL;
-	}
 
 again:
-	value = (char*)malloc(sizeof(char)*len + 1);
-
-	if (value == NULL) {
+	value = (char *)malloc(sizeof(char) * len + 1);
+	if (value == NULL)
 		goto again;
-	}
 
 	if (c->get_keys(c, key, value, len + 1) != len) {
 		free(value);
 		return NULL;
 	}
+
 	return value;
 }
 
-char* go_lxc_get_cgroup_item(struct lxc_container *c, const char *key) {
+char *go_lxc_get_cgroup_item(struct lxc_container *c, const char *key)
+{
 	char *value = NULL;
 
 	int len = c->get_cgroup_item(c, key, NULL, 0);
-	if (len <= 0) {
+	if (len <= 0)
 		return NULL;
-	}
 
 again:
-	value = (char*)malloc(sizeof(char)*len + 1);
-
-	if (value == NULL) {
+	value = (char *)malloc(sizeof(char) * len + 1);
+	if (value == NULL)
 		goto again;
-	}
 
 	if (c->get_cgroup_item(c, key, value, len + 1) != len) {
 		free(value);
 		return NULL;
 	}
+
 	return value;
 }
 


More information about the lxc-devel mailing list