From ac3b725928b6b6c4a1188670a67ed5432744de26 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Tue, 1 Mar 2022 15:47:02 +0800 Subject: [PATCH] hdparm: fix fd leak in sysfs_write_attr() In sysfs_write_attr(), if "fmt[0] != %", will return without close fp. Fix issue: https://gitee.com/src-openeuler/hdparm/issues/I4S2C0 Signed-off-by: Zhiqiang Liu --- sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysfs.c b/sysfs.c index 60b8146..722b2a9 100644 --- a/sysfs.c +++ b/sysfs.c @@ -60,8 +60,9 @@ static int sysfs_write_attr (char *path, const char *attr, const char *fmt, void } if (count < 0) err = errno; - fclose(fp); } + if (!fp) + fclose(fp); if (err && verbose) perror(path); *pathtail = '\0'; return err; -- 1.8.3.1