From: Dhaval Giani Date: Tue, 16 Nov 2010 13:29:46 +0000 (+0100) Subject: v2 [patch 1/6] wrapper.c: Fix memory leaks X-Git-Tag: v0.37~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f70ad595240d11e419d24756df15bcd30cef4c9;p=thirdparty%2Flibcgroup.git v2 [patch 1/6] wrapper.c: Fix memory leaks Steve Grubb was kind enough to do a code review at http://article.gmane.org/gmane.comp.lib.libcg.devel/2485 and spotted a few memory leaks. Take care of them! Reported-by: Steve Grubb Signed-off-by: Dhaval Giani Acked-By: Jan Safranek --- diff --git a/src/wrapper.c b/src/wrapper.c index 00a74bec..83c0030c 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -162,8 +162,10 @@ int cgroup_add_value_int64(struct cgroup_controller *controller, ret = snprintf(cntl_value->value, sizeof(cntl_value->value), "%" PRId64, value); - if (ret >= sizeof(cntl_value->value)) + if (ret >= sizeof(cntl_value->value)) { + free(cntl_value); return ECGINVAL; + } controller->values[controller->index] = cntl_value; controller->index++; @@ -199,8 +201,10 @@ int cgroup_add_value_uint64(struct cgroup_controller *controller, ret = snprintf(cntl_value->value, sizeof(cntl_value->value), "%" PRIu64, value); - if (ret >= sizeof(cntl_value->value)) + if (ret >= sizeof(cntl_value->value)) { + free(cntl_value); return ECGINVAL; + } controller->values[controller->index] = cntl_value; controller->index++; @@ -241,8 +245,10 @@ int cgroup_add_value_bool(struct cgroup_controller *controller, ret = snprintf(cntl_value->value, sizeof(cntl_value->value), "0"); - if (ret >= sizeof(cntl_value->value)) + if (ret >= sizeof(cntl_value->value)) { + free(cntl_value); return ECGINVAL; + } controller->values[controller->index] = cntl_value; controller->index++;