From a4f9b85c4ed1cc5128bcb6650cc8989310558769 Mon Sep 17 00:00:00 2001 From: yangjiaqi Date: Thu, 25 Nov 2021 12:06:31 +0800 Subject: [PATCH 05/17] fix-memory-leak --- src/proc_fuse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/proc_fuse.c b/src/proc_fuse.c index 7372a36..bcd624d 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -278,6 +278,8 @@ static uint64_t get_min_memlimit(const char *cgroup, bool swap) return log_error_errno(0, ENOMEM, "Failed to allocate memory"); retlimit = get_memlimit(copy, swap); + if (retlimit == 0) + return 0; /* * If the cgroup doesn't start with / (probably won't happen), dirname() @@ -346,6 +348,8 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset, prune_init_slice(cgroup); memlimit = get_min_memlimit(cgroup, false); + if (memlimit == 0) + return 0; ret = cgroup_ops->get_memory_current(cgroup_ops, cgroup, &memusage_str); if (ret < 0) @@ -1329,6 +1333,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, return read_file_fuse("/proc/meminfo", buf, size, d); memlimit = get_min_memlimit(cgroup, false); + if (memlimit == 0) + return 0; /* * Following values are allowed to fail, because swapaccount might be @@ -1361,9 +1367,9 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, memusage /= 1024; memlimit /= 1024; + char *printme, lbuf[100]; while (getline(&line, &linelen, f) != -1) { ssize_t l; - char *printme, lbuf[100]; memset(lbuf, 0, 100); if (startswith(line, "MemTotal:")) { -- 2.27.0