linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: neilb@suse.de
Cc: linux-raid@vger.kernel.org, ed.ciechanowski@intel.com,
	marcin.labun@intel.com
Subject: [PATCH 07/13] mdmon: cleanup manage_member() leak
Date: Tue, 22 Dec 2009 16:59:55 -0700	[thread overview]
Message-ID: <20091222235955.31628.72779.stgit@dwillia2-linux.ch.intel.com> (raw)
In-Reply-To: <20091222235807.31628.23231.stgit@dwillia2-linux.ch.intel.com>

free() the results of activate_spare().

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---

 managemon.c |   85 ++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 52 insertions(+), 33 deletions(-)

diff --git a/managemon.c b/managemon.c
index 5958e18..19effe4 100644
--- a/managemon.c
+++ b/managemon.c
@@ -209,16 +209,22 @@ struct metadata_update *update_queue = NULL;
 struct metadata_update *update_queue_handled = NULL;
 struct metadata_update *update_queue_pending = NULL;
 
-void check_update_queue(struct supertype *container)
+static void free_updates(struct metadata_update **update)
 {
-	while (update_queue_handled) {
-		struct metadata_update *this = update_queue_handled;
-		update_queue_handled = this->next;
+	while (*update) {
+		struct metadata_update *this = *update;
+
+		*update = this->next;
 		free(this->buf);
-		if (this->space)
-			free(this->space);
+		free(this->space);
 		free(this);
 	}
+}
+
+void check_update_queue(struct supertype *container)
+{
+	free_updates(&update_queue_handled);
+
 	if (update_queue == NULL &&
 	    update_queue_pending) {
 		update_queue = update_queue_pending;
@@ -376,8 +382,9 @@ static void manage_member(struct mdstat_ent *mdstat,
 
 	if (a->check_degraded) {
 		struct metadata_update *updates = NULL;
-		struct mdinfo *newdev;
+		struct mdinfo *newdev = NULL;
 		struct active_array *newa;
+		struct mdinfo *d;
 
 		a->check_degraded = 0;
 
@@ -385,34 +392,46 @@ static void manage_member(struct mdstat_ent *mdstat,
 		 * to check.
 		 */
 		newdev = a->container->ss->activate_spare(a, &updates);
-		if (newdev) {
-			struct mdinfo *d;
-			/* Cool, we can add a device or several. */
-			newa = duplicate_aa(a);
-			/* suspend recovery - maybe not needed */
-
-			/* Add device to array and set offset/size/slot.
-			 * and open files for each newdev */
-			for (d = newdev; d ; d = d->next) {
-				struct mdinfo *newd;
-				if (sysfs_add_disk(&newa->info, d, 0) < 0)
-					continue;
-				newd = malloc(sizeof(*newd));
-				*newd = *d;
-				newd->next = newa->info.devs;
-				newa->info.devs = newd;
-
-				newd->state_fd = sysfs_open(a->devnum,
-							    newd->sys_name,
-							    "state");
-				newd->prev_state
-					= read_dev_state(newd->state_fd);
-				newd->curr_state = newd->prev_state;
+		if (!newdev)
+			return;
+
+		newa = duplicate_aa(a);
+		if (!newa)
+			goto out;
+		/* Cool, we can add a device or several. */
+
+		/* Add device to array and set offset/size/slot.
+		 * and open files for each newdev */
+		for (d = newdev; d ; d = d->next) {
+			struct mdinfo *newd;
+
+			newd = malloc(sizeof(*newd));
+			if (!newd)
+				continue;
+			if (sysfs_add_disk(&newa->info, d, 0) < 0) {
+				free(newd);
+				continue;
 			}
-			queue_metadata_update(updates);
-			replace_array(a->container, a, newa);
-			sysfs_set_str(&a->info, NULL, "sync_action", "recover");
+			*newd = *d;
+			newd->next = newa->info.devs;
+			newa->info.devs = newd;
+
+			newd->state_fd = sysfs_open(a->devnum, newd->sys_name,
+						    "state");
+			newd->prev_state = read_dev_state(newd->state_fd);
+			newd->curr_state = newd->prev_state;
+		}
+		queue_metadata_update(updates);
+		updates = NULL;
+		replace_array(a->container, a, newa);
+		sysfs_set_str(&a->info, NULL, "sync_action", "recover");
+ out:
+		while (newdev) {
+			d = newdev->next;
+			free(newdev);
+			newdev = d;
 		}
+		free_updates(&updates);
 	}
 }
 


  parent reply	other threads:[~2009-12-22 23:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-22 23:59 [mdadm PATCH 00/13] rebuild / resync checkpointing and other external metadata fixes Dan Williams
2009-12-22 23:59 ` [PATCH 01/13] imsm: catch attempt to auto-layout zero-length arrays Dan Williams
2009-12-22 23:59 ` [PATCH 02/13] imsm: honor orom constraints for auto-layout Dan Williams
2009-12-22 23:59 ` [PATCH 03/13] imsm: fix spare promotion Dan Williams
2009-12-22 23:59 ` [PATCH 04/13] imsm: fix thunderdome segfault Dan Williams
2009-12-22 23:59 ` [PATCH 05/13] util: fix devnum2devname for devnum == 0 Dan Williams
2009-12-22 23:59 ` [PATCH 06/13] imsm: cleanup print_imsm_dev() Dan Williams
2009-12-22 23:59 ` Dan Williams [this message]
2009-12-23  0:00 ` [PATCH 08/13] mdmon: cleanup resync_start Dan Williams
2009-12-23  0:00 ` [PATCH 10/13] Introduce MaxSector Dan Williams
2009-12-23  0:00 ` [PATCH 11/13] Teach sysfs_add_disk() callers to use ->recovery_start versus 'insync' parameter Dan Williams
2009-12-23  0:00 ` [PATCH 12/13] Support external metadata recovery-resume Dan Williams
2009-12-23  0:00 ` [PATCH 13/13] imsm: add support for checkpointing via 'curr_migr_unit' Dan Williams
2009-12-23  0:13 ` [mdadm PATCH 00/13] rebuild / resync checkpointing and other external metadata fixes Dan Williams
2009-12-30  2:56 ` Neil Brown
2009-12-30  7:19   ` Luca Berra
2009-12-30  7:57     ` Neil Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091222235955.31628.72779.stgit@dwillia2-linux.ch.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=ed.ciechanowski@intel.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=marcin.labun@intel.com \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).