]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: move_ptr() in all cases in mapped_hostid_add() 3368/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Apr 2020 12:30:31 +0000 (14:30 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Apr 2020 12:30:31 +0000 (14:30 +0200)
Closes #3366.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 193df3327f494933fa0aaf932a01e20a1ebab32c..45acc71a9113fb4e8a69d41e69829b1e21e79aa7 100644 (file)
@@ -3918,18 +3918,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);
 }