numactl/SOURCES/0004-sysfs.c-don-t-leak-fd-if-fail-in-sysfs_read.patch
2021-12-09 14:00:04 +00:00

30 lines
689 B
Diff

From dfca78c8ee1d21d967b3a51d5488a8e8cd818ec4 Mon Sep 17 00:00:00 2001
From: Pingfan Liu <piliu@redhat.com>
Date: Thu, 10 Jun 2021 11:13:59 +0800
Subject: [PATCH 4/6] sysfs.c: don't leak fd if fail in sysfs_read()
Signed-off-by: Pingfan Liu <piliu@redhat.com>
---
sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysfs.c b/sysfs.c
index f1cdcdc..9ddf50d 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -17,10 +17,10 @@ hidden char *sysfs_read(char *name)
int n;
int fd;
- fd = open(name, O_RDONLY);
buf = malloc(SYSFS_BLOCK);
if (!buf)
return NULL;
+ fd = open(name, O_RDONLY);
n = read(fd, buf, SYSFS_BLOCK - 1);
close(fd);
if (n <= 0) {
--
2.29.2