summaryrefslogtreecommitdiffstats
path: root/lib/sysfs.c
diff options
context:
space:
mode:
authorKarel Zak2012-02-01 13:03:58 +0100
committerKarel Zak2012-02-01 13:03:58 +0100
commit06ae069bc362c25847fb8ccfef6a459165e9f901 (patch)
tree8b1664231455cb7bd2f940c9fdb07b12a8fa45d4 /lib/sysfs.c
parentvipw: don't modify environment, check strtok() return value (diff)
downloadkernel-qcow2-util-linux-06ae069bc362c25847fb8ccfef6a459165e9f901.tar.gz
kernel-qcow2-util-linux-06ae069bc362c25847fb8ccfef6a459165e9f901.tar.xz
kernel-qcow2-util-linux-06ae069bc362c25847fb8ccfef6a459165e9f901.zip
lib/sysfs: fix possible fd leak on error
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/sysfs.c')
-rw-r--r--lib/sysfs.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index ebb3bb508..6e7a1e0ae 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: