From 06ae069bc362c25847fb8ccfef6a459165e9f901 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Feb 2012 13:03:58 +0100 Subject: [PATCH] lib/sysfs: fix possible fd leak on error Signed-off-by: Karel Zak --- lib/sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index ebb3bb508f..6e7a1e0aee 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -148,11 +148,12 @@ int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent) fd = open(path, O_RDONLY); if (fd < 0) goto err; + cxt->dir_fd = fd; + cxt->dir_path = strdup(path); if (!cxt->dir_path) goto err; cxt->devno = devno; - cxt->dir_fd = fd; cxt->parent = parent; return 0; err: -- 2.47.2