From 1758c195057c32476e0e42c5fb5cbfad836a060e Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 9 Apr 2020 14:30:31 +0200 Subject: [PATCH] conf: move_ptr() in all cases in mapped_hostid_add() Closes #3366. Signed-off-by: Christian Brauner --- src/lxc/conf.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) 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); } -- 2.47.2