]> git.proxmox.com Git - mirror_lxc.git/commitdiff
coverity resource leak fixes
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 15 Apr 2013 03:44:09 +0000 (22:44 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 15 Apr 2013 03:44:09 +0000 (22:44 -0500)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/apparmor.c
src/lxc/cgroup.c
src/lxc/conf.c
src/lxc/confile.c

index 11f32d550fe25f248848f7e10aed9c7da9cab0a3..a2d6476729f61abc827b62aef2b0904087501f09 100644 (file)
@@ -36,6 +36,8 @@ again:
        f = fopen(path, "r");
        if (!f) {
                SYSERROR("opening %s\n", path);
+               if (buf)
+                       free(buf);
                return NULL;
        }
        sz += 1024;
index 812bfb80f02696a53559cf5aa908e8bff53df6fa..368214f2440c39a7e25eff598d3d831e558f0335 100644 (file)
@@ -69,8 +69,10 @@ static char *mount_has_subsystem(const struct mntent *mntent)
                return 0;
 
        /* skip the first line, which contains column headings */
-       if (!fgets(line, MAXPATHLEN, f))
+       if (!fgets(line, MAXPATHLEN, f)) {
+               fclose(f);
                return 0;
+       }
 
        while (fgets(line, MAXPATHLEN, f)) {
                c = strchr(line, '\t');
index 33061df22d086c6d6cd13e03b10e403e407e10c8..b6bdd936ba9f11045d3cb17f2f00570d055150d3 100644 (file)
@@ -309,6 +309,7 @@ static int run_buffer(char *buffer)
        output = malloc(LXC_LOG_BUFFER_SIZE);
        if (!output) {
                ERROR("failed to allocate memory for script output");
+               pclose(f);
                return -1;
        }
 
@@ -535,6 +536,7 @@ static int mount_rootfs_file(const char *rootfs, const char *target)
                if (errno != ENXIO) {
                        WARN("unexpected error for ioctl on '%s': %m",
                             direntp->d_name);
+                       close(fd);
                        continue;
                }
 
@@ -792,6 +794,7 @@ static int setup_rootfs_pivot_root_cb(char *buffer, void *data)
        listentry->elem = strdup(mountpoint);
        if (!listentry->elem) {
                SYSERROR("strdup failed");
+               free(listentry);
                return -1;
        }
        lxc_list_add_tail(mountlist, listentry);
@@ -1053,8 +1056,10 @@ int detect_shared_rootfs(void)
                if (strcmp(p+1, "/") == 0) {
                        // this is '/'.  is it shared?
                        p = index(p2+1, ' ');
-                       if (strstr(p, "shared:"))
+                       if (strstr(p, "shared:")) {
+                               fclose(f);
                                return 1;
+                       }
                }
        }
        fclose(f);
index ba017074a513556eb34efaf4f21d3885754e8a20..d0a404f4a713b9de62dc3da491beefc0fe096b0d 100644 (file)
@@ -1249,8 +1249,10 @@ static int config_mount(const char *key, const char *value,
                return -1;
 
        mntelem = strdup(value);
-       if (!mntelem)
+       if (!mntelem) {
+               free(mntlist);
                return -1;
+       }
        mntlist->elem = mntelem;
 
        lxc_list_add_tail(&lxc_conf->mount_list, mntlist);