diff options
author | Adam Kwolek <adam.kwolek@intel.com> | 2011-03-18 02:32:16 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-03-18 02:32:16 +0100 |
commit | 983fff45a163e35f1a4d309b39ee9a0cbbc2195a (patch) | |
tree | 9117d15f814d49f4a0900864628f61e45e4f5c0d | |
parent | Manage: fix the mess I made in earlier patch. (diff) | |
download | mdadm-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.c | 2 | ||||
-rw-r--r-- | Create.c | 2 | ||||
-rw-r--r-- | Grow.c | 2 | ||||
-rw-r--r-- | Incremental.c | 10 | ||||
-rw-r--r-- | Manage.c | 2 | ||||
-rw-r--r-- | Monitor.c | 2 | ||||
-rw-r--r-- | msg.c | 14 | ||||
-rw-r--r-- | msg.h | 1 |
8 files changed, 24 insertions, 11 deletions
@@ -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; } @@ -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); @@ -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; } @@ -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 { @@ -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; @@ -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); @@ -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); |