63 lines
1.8 KiB
Diff
63 lines
1.8 KiB
Diff
|
|
From 9a4aac68658a61df1c97ecdd7d9a9e67f572fb3e Mon Sep 17 00:00:00 2001
|
||
|
|
From: Chris White <chwhite@redhat.com>
|
||
|
|
Date: Fri, 25 Jun 2021 17:32:10 +0000
|
||
|
|
Subject: [PATCH] lib: Fixed memory leaks in lib/sysfs_attr.c
|
||
|
|
|
||
|
|
- read_dir_links() has a case where the function returns before
|
||
|
|
closing the dir pointer.
|
||
|
|
|
||
|
|
- sysfs_read_dir_subdirs() has a case where the function returns
|
||
|
|
before closing the dev pointer.
|
||
|
|
|
||
|
|
- read_dir_subdirs() has a case where the function returns before
|
||
|
|
closing the dir pointer.
|
||
|
|
|
||
|
|
- get_attributes_list() has a case where the function returns before
|
||
|
|
closing the dir pointer.
|
||
|
|
|
||
|
|
Warned-by: covscan
|
||
|
|
Signed-off-by: Chris White <chwhite@redhat.com>
|
||
|
|
---
|
||
|
|
lib/sysfs_attr.c | 4 ++++
|
||
|
|
1 file changed, 4 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/lib/sysfs_attr.c b/lib/sysfs_attr.c
|
||
|
|
index fe27dbe..82aacf4 100644
|
||
|
|
--- a/lib/sysfs_attr.c
|
||
|
|
+++ b/lib/sysfs_attr.c
|
||
|
|
@@ -415,6 +415,7 @@ struct dlist *read_dir_links(const char *path)
|
||
|
|
(SYSFS_NAME_LEN, sysfs_del_name);
|
||
|
|
if (!linklist) {
|
||
|
|
dbg_printf("Error creating list\n");
|
||
|
|
+ closedir(dir);
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -470,6 +471,7 @@ struct sysfs_device *sysfs_read_dir_subdirs(const char *path)
|
||
|
|
dir = opendir(path);
|
||
|
|
if (!dir) {
|
||
|
|
dbg_printf("Error opening directory %s\n", path);
|
||
|
|
+ sysfs_close_device(dev);
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
while ((dirent = readdir(dir)) != NULL) {
|
||
|
|
@@ -524,6 +526,7 @@ struct dlist *read_dir_subdirs(const char *path)
|
||
|
|
(SYSFS_NAME_LEN, sysfs_del_name);
|
||
|
|
if (!dirlist) {
|
||
|
|
dbg_printf("Error creating list\n");
|
||
|
|
+ closedir(dir);
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@@ -573,6 +576,7 @@ struct dlist *get_attributes_list(struct dlist *alist, const char *path)
|
||
|
|
sysfs_del_attribute);
|
||
|
|
if (!alist) {
|
||
|
|
dbg_printf("Error creating list\n");
|
||
|
|
+ closedir(dir);
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|