[CRIU] [PATCH 1/8] cgroups: don't leak memory on a error path

Andrei Vagin avagin at openvz.org
Fri Feb 16 10:21:13 MSK 2018


[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

From: Andrei Vagin <avagin at virtuozzo.com>

CID 161693 (#1 of 1): Resource leak (RESOURCE_LEAK)
5. leaked_storage: Variable new going out of scope leaks the storage it points to.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 lib/c/criu.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/c/criu.c b/lib/c/criu.c
index 931d691ec..84b7ad595 100644
--- a/lib/c/criu.c
+++ b/lib/c/criu.c
@@ -771,17 +771,21 @@ int criu_local_add_cg_props_file(criu_opts *opts, char *path)

 int criu_local_add_cg_dump_controller(criu_opts *opts, char *name)
 {
-       char **new;
+       char **new, *ctrl_name;
        size_t nr;

+       ctrl_name = xstrdup(name);
+       if (!ctrl_name)
+               return -ENOMEM;
+
        nr = opts->rpc->n_cgroup_dump_controller + 1;
        new = realloc(opts->rpc->cgroup_dump_controller, nr * sizeof(char *));
-       if (!new)
+       if (!new) {
+               xfree(ctrl_name);
                return -ENOMEM;
+       }

-       new[opts->rpc->n_cgroup_dump_controller] = strdup(name);
-       if (!new[opts->rpc->n_cgroup_dump_controller])
-               return -ENOMEM;
+       new[opts->rpc->n_cgroup_dump_controller] = ctrl_name;

        opts->rpc->n_cgroup_dump_controller = nr;
        opts->rpc->cgroup_dump_controller = new;
--
2.13.6




More information about the CRIU mailing list