[lxc-devel] [lxc/master] lxccontainer.c: Use calloc instead of malloc/memset

marcosps on Github lxc-bot at linuxcontainers.org
Thu Nov 23 01:39:32 UTC 2017


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/20171123/20e7de0d/attachment.bin>
-------------- next part --------------
From e15655b67ad46554bdd5ed9e28eb41da081b80e1 Mon Sep 17 00:00:00 2001
From: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
Date: Wed, 22 Nov 2017 23:38:30 -0200
Subject: [PATCH] lxccontainer.c: Use calloc instead of malloc/memset

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
---
 src/lxc/lxccontainer.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 413dd375b..b3e3222db 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -4408,11 +4408,10 @@ static int do_lxcapi_migrate(struct lxc_container *c, unsigned int cmd,
 	 * to initialize.
 	 */
 	if (size < sizeof(*opts)) {
-		valid_opts = malloc(sizeof(*opts));
+		valid_opts = calloc(1, sizeof(*opts));
 		if (!valid_opts)
 			return -ENOMEM;
 
-		memset(valid_opts, 0, sizeof(*opts));
 		memcpy(valid_opts, opts, size);
 	}
 
@@ -4516,12 +4515,11 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
 	if (!name)
 		return NULL;
 
-	c = malloc(sizeof(*c));
+	c = calloc(1, sizeof(*c));
 	if (!c) {
 		fprintf(stderr, "failed to malloc lxc_container\n");
 		return NULL;
 	}
-	memset(c, 0, sizeof(*c));
 
 	if (configpath)
 		c->config_path = strdup(configpath);


More information about the lxc-devel mailing list