]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
bindings: fix memory leak in proc_loadavg_read()
authorJakub Skokan <jakub.skokan@havefun.cz>
Mon, 11 Jun 2018 13:12:22 +0000 (15:12 +0200)
committerJakub Skokan <jakub.skokan@havefun.cz>
Tue, 12 Jun 2018 17:56:17 +0000 (19:56 +0200)
Signed-off-by: Jakub Skokan <jakub.skokan@havefun.cz>
bindings.c

index b20eaa053b92877683163a27206143c8c9eed36a..f7d3194b9fffdbdab62e0c6241786cd2e3e680f7 100644 (file)
@@ -4552,7 +4552,7 @@ static int proc_loadavg_read(char *buf, size_t size, off_t offset,
        char *cache = d->buf;
        struct load_node *n;
        int hash;
-       int cfd;
+       int cfd, rv = 0;
        unsigned long a, b, c;
 
        if (offset) {
@@ -4587,7 +4587,8 @@ static int proc_loadavg_read(char *buf, size_t size, off_t offset,
                         * because delete is not allowed before read has ended.
                         */
                        pthread_rwlock_unlock(&load_hash[hash].rdlock);
-                       return 0;
+                       rv = 0;
+                       goto err;
                }
                do {
                        n = malloc(sizeof(struct load_node));
@@ -4617,7 +4618,8 @@ static int proc_loadavg_read(char *buf, size_t size, off_t offset,
        pthread_rwlock_unlock(&load_hash[hash].rdlock);
        if (total_len < 0 || total_len >=  d->buflen) {
                lxcfs_error("%s\n", "Failed to write to cache");
-               return 0;
+               rv = 0;
+               goto err;
        }
        d->size = (int)total_len;
        d->cached = 1;
@@ -4625,7 +4627,11 @@ static int proc_loadavg_read(char *buf, size_t size, off_t offset,
        if (total_len > size)
                total_len = size;
        memcpy(buf, d->buf, total_len);
-       return total_len;
+       rv = total_len;
+
+err:
+       free(cg);
+       return rv;
 }
 /* Return a positive number on success, return 0 on failure.*/
 pthread_t load_daemon(int load_use)