cmd: use goto for cleanup in lxc-usernsexec

parent 0cf1cbf2
...@@ -196,14 +196,14 @@ static int parse_map(char *map) ...@@ -196,14 +196,14 @@ static int parse_map(char *map)
*/ */
static int read_default_map(char *fnam, int which, char *user) static int read_default_map(char *fnam, int which, char *user)
{ {
int ret;
size_t len; size_t len;
char *p1, *p2; char *p1, *p2;
FILE *fin; FILE *fin;
struct id_map *newmap; int ret = -1;
size_t sz = 0; size_t sz = 0;
char *line = NULL; char *line = NULL;
struct lxc_list *tmp = NULL; struct lxc_list *tmp = NULL;
struct id_map *newmap = NULL;
fin = fopen(fnam, "r"); fin = fopen(fnam, "r");
if (!fin) if (!fin)
...@@ -223,46 +223,38 @@ static int read_default_map(char *fnam, int which, char *user) ...@@ -223,46 +223,38 @@ static int read_default_map(char *fnam, int which, char *user)
continue; continue;
newmap = malloc(sizeof(*newmap)); newmap = malloc(sizeof(*newmap));
if (!newmap) { if (!newmap)
fclose(fin); goto on_error;
free(line);
return -1;
}
ret = lxc_safe_ulong(p1 + 1, &newmap->hostid); ret = lxc_safe_ulong(p1 + 1, &newmap->hostid);
if (ret < 0) { if (ret < 0)
fclose(fin); goto on_error;
free(line);
return -1;
}
ret = lxc_safe_ulong(p2 + 1, &newmap->range); ret = lxc_safe_ulong(p2 + 1, &newmap->range);
if (ret < 0) { if (ret < 0)
fclose(fin); goto on_error;
free(line);
return -1;
}
newmap->nsid = 0; newmap->nsid = 0;
newmap->idtype = which; newmap->idtype = which;
ret = -1;
tmp = malloc(sizeof(*tmp)); tmp = malloc(sizeof(*tmp));
if (!tmp) { if (!tmp)
fclose(fin); goto on_error;
free(line);
free(newmap);
return -1;
}
tmp->elem = newmap; tmp->elem = newmap;
lxc_list_add_tail(&active_map, tmp); lxc_list_add_tail(&active_map, tmp);
break; break;
} }
free(line); ret = 0;
on_error:
fclose(fin); fclose(fin);
free(line);
free(newmap);
return 0; return ret;
} }
static int find_default_map(void) static int find_default_map(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment