summaryrefslogtreecommitdiffstats
path: root/sysfs.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2008-10-02 03:49:53 +0200
committerDan Williams <dan.j.williams@intel.com>2008-10-15 23:15:52 +0200
commit1e4bc070a73716292c1681a86524f46f656f8acb (patch)
treedcc03fc5eb334191a3f0f179d1adbe5a499cbc1e /sysfs.c
parentnon-trivial warn_unused_result fix, prepare_update (diff)
downloadmdadm-1e4bc070a73716292c1681a86524f46f656f8acb.tar.xz
mdadm-1e4bc070a73716292c1681a86524f46f656f8acb.zip
sysfs_open leaks devnum2devname() result
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'sysfs.c')
-rw-r--r--sysfs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sysfs.c b/sysfs.c
index 23d2f18d..58c84e26 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -61,8 +61,12 @@ int sysfs_open(int devnum, char *devname, char *attr)
{
char fname[50];
int fd;
+ char *mdname = devnum2devname(devnum);
- sprintf(fname, "/sys/block/%s/md/", devnum2devname(devnum));
+ if (!mdname)
+ return -1;
+
+ sprintf(fname, "/sys/block/%s/md/", mdname);
if (devname) {
strcat(fname, devname);
strcat(fname, "/");
@@ -71,6 +75,7 @@ int sysfs_open(int devnum, char *devname, char *attr)
fd = open(fname, O_RDWR);
if (fd < 0 && errno == EACCES)
fd = open(fname, O_RDONLY);
+ free(mdname);
return fd;
}