The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3382

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Fixes: Coverity 1461760.
Fixes: Coverity 1461762.
Fixes: Coverity 1461763.
Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 47649d5bba30ed4b9bcbbaea146dee5fe0150f6d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Wed, 15 Apr 2020 14:54:35 +0200
Subject: [PATCH] conf: correctly cleanup memory in get_minimal_idmap()

Fixes: Coverity 1461760.
Fixes: Coverity 1461762.
Fixes: Coverity 1461763.
Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/lxc/conf.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 474b01f92e..20d1583fc4 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -3985,45 +3985,35 @@ static struct lxc_list *get_minimal_idmap(const struct 
lxc_conf *conf,
        tmplist = malloc(sizeof(*tmplist));
        if (!tmplist)
                return NULL;
-       lxc_list_add_elem(tmplist, container_root_uid);
+       /* idmap will now keep track of that memory. */
+       lxc_list_add_elem(tmplist, move_ptr(host_uid_map));
        lxc_list_add_tail(idmap, tmplist);
 
        if (container_root_uid) {
-               /* idmap will now keep track of that memory. */
-               move_ptr(container_root_uid);
-
                /* Add container root to the map. */
                tmplist = malloc(sizeof(*tmplist));
                if (!tmplist)
                        return NULL;
-               lxc_list_add_elem(tmplist, host_uid_map);
+               /* idmap will now keep track of that memory. */
+               lxc_list_add_elem(tmplist, move_ptr(container_root_uid));
                lxc_list_add_tail(idmap, tmplist);
        }
-       /* idmap will now keep track of that memory. */
-       move_ptr(container_root_uid);
-       /* idmap will now keep track of that memory. */
-       move_ptr(host_uid_map);
 
        tmplist = malloc(sizeof(*tmplist));
        if (!tmplist)
                return NULL;
-       lxc_list_add_elem(tmplist, container_root_gid);
+       /* idmap will now keep track of that memory. */
+       lxc_list_add_elem(tmplist, move_ptr(host_gid_map));
        lxc_list_add_tail(idmap, tmplist);
 
        if (container_root_gid) {
-               /* idmap will now keep track of that memory. */
-               move_ptr(container_root_gid);
-
                tmplist = malloc(sizeof(*tmplist));
                if (!tmplist)
                        return NULL;
-               lxc_list_add_elem(tmplist, host_gid_map);
+               /* idmap will now keep track of that memory. */
+               lxc_list_add_elem(tmplist, move_ptr(container_root_gid));
                lxc_list_add_tail(idmap, tmplist);
        }
-       /* idmap will now keep track of that memory. */
-       move_ptr(container_root_gid);
-       /* idmap will now keep track of that memory. */
-       move_ptr(host_gid_map);
 
        TRACE("Allocated minimal idmapping for ns uid %d and ns gid %d", nsuid, 
nsgid);
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to