Unverified Commit f6812e7f by Serge Hallyn Committed by GitHub

Merge pull request #2011 from brauner/generic/coverity

coverity: bugfixes
parents fb398f07 2d7bf744
......@@ -599,6 +599,7 @@ static char *lxc_attach_getpwshell(uid_t uid)
if (waitpid(pid, &status, 0) < 0) {
if (errno == EINTR)
goto again;
free(result);
return NULL;
}
......@@ -607,14 +608,20 @@ static char *lxc_attach_getpwshell(uid_t uid)
* don't.
*/
if (!WIFEXITED(status))
if (!WIFEXITED(status)) {
free(result);
return NULL;
}
if (WEXITSTATUS(status) != 0)
if (WEXITSTATUS(status) != 0) {
free(result);
return NULL;
}
if (!found)
if (!found) {
free(result);
return NULL;
}
return result;
} else {
......
......@@ -555,7 +555,10 @@ static bool find_hierarchy_mountpts( struct cgroup_meta_data *meta_data, char **
}
}
k = lxc_array_len((void **)h->all_mount_points);
if (h)
k = lxc_array_len((void **)h->all_mount_points);
else
k = 0;
r = lxc_grow_array((void ***)&h->all_mount_points, &h->all_mount_point_capacity, k + 1, 4);
if (r < 0)
goto out;
......
......@@ -526,6 +526,7 @@ static bool filter_and_set_cpus(char *path, bool am_initialized)
copy_parent:
*lastslash = oldv;
free(fpath);
fpath = must_make_path(path, "cpuset.cpus", NULL);
ret = lxc_write_to_file(fpath, cpulist, strlen(cpulist), false);
if (ret < 0) {
......@@ -1748,6 +1749,7 @@ static bool cgfsng_mount(void *hdata, const char *root, int type)
path2 = must_make_path(controllerpath, h->base_cgroup, d->container_cgroup, NULL);
if (mkdir_p(path2, 0755) < 0) {
free(controllerpath);
free(path2);
goto bad;
}
......
......@@ -325,7 +325,8 @@ static int lxc_cmd(const char *name, struct lxc_cmd_rr *cmd, int *stopped,
*stopped = 1;
out:
if (!stay_connected || ret <= 0)
close(client_fd);
if (client_fd >= 0)
close(client_fd);
if (stay_connected && ret > 0)
cmd->rsp.ret = client_fd;
......
......@@ -975,7 +975,7 @@ static int lxc_clear_nic(struct lxc_conf *c, const char *key)
if (!p1 || *(p1+1) == '\0')
return -1;
if (!p1 && it) {
if (it) {
lxc_remove_nic(it);
} else if (strcmp(p1, ".ipv4") == 0) {
struct lxc_list *it2,*next;
......
......@@ -848,10 +848,12 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
/* ... otherwise use default_args. */
if (!argv) {
if (useinit)
if (useinit) {
ERROR("No valid init detected");
lxc_free_handler(handler);
return false;
else
argv = default_args;
}
argv = default_args;
}
/* I'm not sure what locks we want here.Any? Is liblxc's locking enough
......
......@@ -1915,6 +1915,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *lxc_mkifname(char *template)
{
int ret;
unsigned int seed;
FILE *urandom;
struct ifaddrs *ifa, *ifaddr;
......@@ -1926,7 +1927,11 @@ char *lxc_mkifname(char *template)
return NULL;
/* Get all the network interfaces. */
getifaddrs(&ifaddr);
ret = getifaddrs(&ifaddr);
if (ret < 0) {
ERROR("%s - Failed to get network interfaces", strerror(errno));
return NULL;
}
/* Initialize the random number generator. */
urandom = fopen("/dev/urandom", "r");
......
......@@ -226,14 +226,16 @@ restart:
continue;
/* Keep state clients that wait on reboots. */
lxc_list_for_each(cur, &conf->state_clients) {
struct lxc_state_client *client = cur->elem;
if (conf) {
lxc_list_for_each(cur, &conf->state_clients) {
struct lxc_state_client *client = cur->elem;
if (client->clientfd != fd)
continue;
if (client->clientfd != fd)
continue;
matched = true;
break;
matched = true;
break;
}
}
if (matched)
......
......@@ -417,7 +417,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
if (!mkdtemp(randname))
return -1;
if (chmod(randname, 0770) < 0) {
remove(randname);
(void)remove(randname);
return -1;
}
arg->newname = randname + strlen(arg->newpath) + 1;
......
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