From: Christian Brauner Date: Thu, 9 Apr 2020 12:30:31 +0000 (+0200) Subject: conf: move_ptr() in all cases in mapped_hostid_add() X-Git-Tag: lxc-5.0.0~460^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3368%2Fhead;p=thirdparty%2Flxc.git conf: move_ptr() in all cases in mapped_hostid_add() Closes #3366. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 193df3327..45acc71a9 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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); }