From 62a38dfff0c37a62877f4fe80192ac140823d75f Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 20 Aug 2018 14:24:55 +0200 Subject: [PATCH] cmd: use goto for cleanup in lxc-usernsexec Signed-off-by: Christian Brauner --- src/lxc/cmd/lxc_usernsexec.c | 42 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c index 4909a9324..bdfef0fb2 100644 --- a/src/lxc/cmd/lxc_usernsexec.c +++ b/src/lxc/cmd/lxc_usernsexec.c @@ -196,14 +196,14 @@ static int parse_map(char *map) */ static int read_default_map(char *fnam, int which, char *user) { - int ret; size_t len; char *p1, *p2; FILE *fin; - struct id_map *newmap; + int ret = -1; size_t sz = 0; char *line = NULL; struct lxc_list *tmp = NULL; + struct id_map *newmap = NULL; fin = fopen(fnam, "r"); if (!fin) @@ -223,46 +223,38 @@ static int read_default_map(char *fnam, int which, char *user) continue; newmap = malloc(sizeof(*newmap)); - if (!newmap) { - fclose(fin); - free(line); - return -1; - } + if (!newmap) + goto on_error; ret = lxc_safe_ulong(p1 + 1, &newmap->hostid); - if (ret < 0) { - fclose(fin); - free(line); - return -1; - } + if (ret < 0) + goto on_error; ret = lxc_safe_ulong(p2 + 1, &newmap->range); - if (ret < 0) { - fclose(fin); - free(line); - return -1; - } + if (ret < 0) + goto on_error; newmap->nsid = 0; newmap->idtype = which; + ret = -1; tmp = malloc(sizeof(*tmp)); - if (!tmp) { - fclose(fin); - free(line); - free(newmap); - return -1; - } + if (!tmp) + goto on_error; tmp->elem = newmap; lxc_list_add_tail(&active_map, tmp); break; } - free(line); + ret = 0; + +on_error: fclose(fin); + free(line); + free(newmap); - return 0; + return ret; } static int find_default_map(void) -- 2.47.2