fix dev read memory leak in container

Signed-off-by: zhangsong234 <zhangsong34@huawei.com>
This commit is contained in:
zhangsong234 2022-05-11 15:58:57 +08:00 committed by songyanting
parent 9ca77132b9
commit 5acb409bc7
2 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,59 @@
From d67982ddf6d742b92799d1fb2e4c89e8ff87d95b Mon Sep 17 00:00:00 2001
From: zhangsong234 <zhangsong34@huawei.com>
Date: Wed, 11 May 2022 15:55:47 +0800
Subject: [PATCH] fix dev read memory leak in container
Signed-off-by: zhangsong234 <zhangsong34@huawei.com>
---
src/proc_fuse.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0f66c40..6051e9a 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -497,7 +497,7 @@ struct devinfo* container_dev_read(pid_t pid) {
struct dirent *ptr;
struct stat dev_stat;
struct devinfo *head = NULL, *end;
- char fpath[100], dev_name[100];
+ char fpath[100], dev_name[101];
pid_t child_pid;
int mypipe[2];
int dev_num;
@@ -558,7 +558,7 @@ struct devinfo* container_dev_read(pid_t pid) {
}
closedir(dir);
stat("/", &dev_stat);
- dev_num = dev_stat.st_dev & (~0xf);
+ dev_num = dev_stat.st_dev;
fprintf(stream, "sda %d end 0 ", dev_num);
fflush(stream);
child_out:
@@ -574,6 +574,7 @@ child_out:
}
wait_for_pid(child_pid);
child_pid = 0;
+ memset(dev_name, 0, sizeof(dev_name));
while (fscanf(stream, "%100s%d", dev_name, &dev_num) == 2) {
if (dev_num == 0) {
break;
@@ -593,6 +594,7 @@ child_out:
end->name = must_copy_string(dev_name);
end->major = major(dev_num);
end->minor = minor(dev_num);
+ memset(dev_name, 0, sizeof(dev_name));
}
err:
if (stream)
@@ -883,6 +885,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (total_len > size)
total_len = size;
memcpy(buf, d->buf, total_len);
+ free_devinfo_list(container_devinfo);
return total_len;
}
--
1.8.3.1

View File

@ -4,7 +4,7 @@
#Basic Information
Name: lxcfs
Version: 4.0.11
Release: 2
Release: 3
Summary: FUSE filesystem for LXC
License: LGPL 2.1+
URL: http://linuxcontainers.org
@ -28,6 +28,7 @@ Patch9015: 0015-lxcfs-adapt-4.18-kernel.patch
Patch9016: 0016-remove-lxcfs-tools-dependency-for-common-use.patch
Patch9017: 0017-proc_fuse-fix-wait-child-process-hang.patch
Patch9018: 0018-fix-deadlock-problem-when-subprocess-exit.patch
Patch9019: 0019-fix-dev-read-memory-leak-in-container.patch
#Dependency
BuildRequires: autoconf automake libtool help2man
@ -89,6 +90,9 @@ fi
%{_unitdir}/*
%changelog
* Wed May 11 2022 zhangsong234 <zhangsong34@huawei.com> - 4.0.11-3
- fix dev read memory leak in container
* Fri Dec 17 2021 yangjiaqi <yangjiaqi16@huawei.com> - 4.0.11-2
- fix deadlock caused by subprocess calling lxcfs_exit