]> git.proxmox.com Git - mirror_lxc.git/commitdiff
conf: move_ptr() in all cases in mapped_hostid_add()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Apr 2020 12:30:31 +0000 (14:30 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 9 Apr 2020 22:28:51 +0000 (18:28 -0400)
Closes #3366.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index fdeadb597ffe0aae578c81c4d51ddb319a2088b9..e32ca5cab372bef111337233fb5d13a8fe527375 100644 (file)
@@ -3915,18 +3915,19 @@ static struct id_map *mapped_hostid_add(const struct lxc_conf *conf, uid_t id,
 
        /* Reuse existing mapping. */
        tmp = find_mapped_hostid_entry(conf, id, type);
-       if (tmp)
-               return memcpy(entry, tmp, sizeof(*entry));
-
-       /* Find new mapping. */
-       hostid_mapped = find_unmapped_nsid(conf, type);
-       if (hostid_mapped < 0)
-               return log_debug(NULL, "Failed to find free mapping for id %d", id);
-
-       entry->idtype = type;
-       entry->nsid = hostid_mapped;
-       entry->hostid = (unsigned long)id;
-       entry->range = 1;
+       if (tmp) {
+               memcpy(entry, tmp, sizeof(*entry));
+       } else {
+               /* Find new mapping. */
+               hostid_mapped = find_unmapped_nsid(conf, type);
+               if (hostid_mapped < 0)
+                       return log_debug(NULL, "Failed to find free mapping for id %d", id);
+
+               entry->idtype = type;
+               entry->nsid = hostid_mapped;
+               entry->hostid = (unsigned long)id;
+               entry->range = 1;
+       }
 
        return move_ptr(entry);
 }