summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Kwolek <adam.kwolek@intel.com>2011-03-18 02:32:16 +0100
committerNeilBrown <neilb@suse.de>2011-03-18 02:32:16 +0100
commit983fff45a163e35f1a4d309b39ee9a0cbbc2195a (patch)
tree9117d15f814d49f4a0900864628f61e45e4f5c0d
parentManage: fix the mess I made in earlier patch. (diff)
downloadmdadm-983fff45a163e35f1a4d309b39ee9a0cbbc2195a.tar.xz
mdadm-983fff45a163e35f1a4d309b39ee9a0cbbc2195a.zip
FIX: ping_monitor() usage causes memory leaks
When for ping_monitor() input devnum2devname() is used, received string pointer should be passed to free() for memory release. It is not made in several places. This use case should have function to avoid memory leak. Signed-off-by: Adam Kwolek <adam.kwolek@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to '')
-rw-r--r--Assemble.c2
-rw-r--r--Create.c2
-rw-r--r--Grow.c2
-rw-r--r--Incremental.c10
-rw-r--r--Manage.c2
-rw-r--r--Monitor.c2
-rw-r--r--msg.c14
-rw-r--r--msg.h1
8 files changed, 24 insertions, 11 deletions
diff --git a/Assemble.c b/Assemble.c
index bfc879c7..ee0346a5 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -1598,7 +1598,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
if (!err) {
if (!mdmon_running(st->container_dev))
start_mdmon(st->container_dev);
- ping_monitor(devnum2devname(st->container_dev));
+ ping_monitor_by_id(st->container_dev);
}
break;
}
diff --git a/Create.c b/Create.c
index 6349f865..9f344256 100644
--- a/Create.c
+++ b/Create.c
@@ -929,7 +929,7 @@ int Create(struct supertype *st, char *mddev,
if (need_mdmon)
start_mdmon(st->container_dev);
- ping_monitor(devnum2devname(st->container_dev));
+ ping_monitor_by_id(st->container_dev);
close(container_fd);
}
wait_for(chosen_name, mdfd);
diff --git a/Grow.c b/Grow.c
index 40e693ed..b6395850 100644
--- a/Grow.c
+++ b/Grow.c
@@ -3416,7 +3416,7 @@ int Grow_continue(int mdfd, struct supertype *st, struct mdinfo *info,
if (!mdmon_running(st->container_dev))
start_mdmon(st->container_dev);
- ping_monitor(devnum2devname(st->container_dev));
+ ping_monitor_by_id(st->container_dev);
if (info->reshape_active == 2) {
diff --git a/Incremental.c b/Incremental.c
index 300bdca7..72180607 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -438,7 +438,7 @@ int Incremental(char *devname, int verbose, int runstop,
/* 7/ Is there enough devices to possibly start the array? */
/* 7a/ if not, finish with success. */
if (info.array.level == LEVEL_CONTAINER) {
- char *devname = NULL;
+ int devnum;
/* Try to assemble within the container */
map_unlock(&map);
sysfs_uevent(&info, "change");
@@ -448,7 +448,7 @@ int Incremental(char *devname, int verbose, int runstop,
chosen_name, info.array.working_disks);
wait_for(chosen_name, mdfd);
if (st->ss->external)
- devname = devnum2devname(fd2devnum(mdfd));
+ devnum = fd2devnum(mdfd);
close(mdfd);
sysfs_free(sra);
rv = Incremental(chosen_name, verbose, runstop,
@@ -460,10 +460,8 @@ int Incremental(char *devname, int verbose, int runstop,
rv = 0;
/* after spare is added, ping monitor for external metadata
* so that it can eg. try to rebuild degraded array */
- if (st->ss->external) {
- ping_monitor(devname);
- free(devname);
- }
+ if (st->ss->external)
+ ping_monitor_by_id(devnum);
return rv;
}
diff --git a/Manage.c b/Manage.c
index a679c24c..5fd7014a 100644
--- a/Manage.c
+++ b/Manage.c
@@ -932,7 +932,7 @@ int Manage_subdevs(char *devname, int fd,
sysfs_free(sra);
return 1;
}
- ping_monitor(devnum2devname(devnum));
+ ping_monitor_by_id(devnum);
sysfs_free(sra);
close(container_fd);
} else {
diff --git a/Monitor.c b/Monitor.c
index d3795b17..3f211b5b 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -975,7 +975,7 @@ int Wait(char *dev)
if (is_subarray(&e->metadata_version[9]))
ping_monitor(&e->metadata_version[9]);
else
- ping_monitor(devnum2devname(devnum));
+ ping_monitor_by_id(devnum);
}
free_mdstat(ms);
return rv;
diff --git a/msg.c b/msg.c
index a1f4bc6e..a10c930d 100644
--- a/msg.c
+++ b/msg.c
@@ -213,6 +213,20 @@ int ping_monitor(char *devname)
return err;
}
+/* ping monitor using device number */
+int ping_monitor_by_id(int devnum)
+{
+ int err = -1;
+ char *container = devnum2devname(devnum);
+
+ if (container) {
+ err = ping_monitor(container);
+ free(container);
+ }
+
+ return err;
+}
+
static char *ping_monitor_version(char *devname)
{
int sfd = connect_monitor(devname);
diff --git a/msg.h b/msg.h
index 91a77987..c6d037d9 100644
--- a/msg.h
+++ b/msg.h
@@ -27,6 +27,7 @@ extern int ack(int fd, int tmo);
extern int wait_reply(int fd, int tmo);
extern int connect_monitor(char *devname);
extern int ping_monitor(char *devname);
+extern int ping_monitor_by_id(int devnum);
extern int block_subarray(struct mdinfo *sra);
extern int unblock_subarray(struct mdinfo *sra, const int unfreeze);
extern int block_monitor(char *container, const int freeze);