NeilBrown: Free some malloced memory that wasn't being freed.

Martin F. Krafft madduck at alioth.debian.org
Tue Oct 27 19:21:40 UTC 2009


Module: mdadm
Branch: master
Commit: 0eb26465c0a14d707ca00f4f7bcdb67bde36f706
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=0eb26465c0a14d707ca00f4f7bcdb67bde36f706

Author: NeilBrown <neilb at suse.de>
Date:   Thu Oct 22 11:00:56 2009 +1100

Free some malloced memory that wasn't being freed.

As mdadm is normally a short-lived program it isn't always necessary
to free memory that was allocated, as the 'exit()' call will
automatically free everything.  But it is more obviously correct if
the 'free' is there.
So this patch add a few calls to 'free'

Signed-off-by: NeilBrown <neilb at suse.de>

---

 Detail.c |    1 +
 Manage.c |    4 +++-
 mdopen.c |    5 ++++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Detail.c b/Detail.c
index e41ad1b..544cfdb 100644
--- a/Detail.c
+++ b/Detail.c
@@ -541,6 +541,7 @@ This is pretty boring
 		    1, avail, avail_disks))
 		rv = 2;
 
+	free(disks);
 out:
 	close(fd);
 	return rv;
diff --git a/Manage.c b/Manage.c
index 3aa09bc..84eb3ab 100644
--- a/Manage.c
+++ b/Manage.c
@@ -140,7 +140,7 @@ static void remove_devices(int devnum, char *path)
 		strcpy(path2, path);
 		pe = path2 + strlen(path2);
 	} else
-		path = NULL;
+		path2 = path = NULL;
 	
 	for (part = 0; part < 16; part++) {
 		if (part) {
@@ -161,6 +161,7 @@ static void remove_devices(int devnum, char *path)
 				unlink(path2);
 		}
 	}
+	free(path2);
 }
 	
 
@@ -667,6 +668,7 @@ int Manage_subdevs(char *devname, int fd,
 						disc.state |= (1<<MD_DISK_SYNC);
 						break;
 					}
+				free(used);
 			}
 			if (dv->writemostly == 1)
 				disc.state |= (1 << MD_DISK_WRITEMOSTLY);
diff --git a/mdopen.c b/mdopen.c
index ed53d6f..21baf5d 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -43,7 +43,7 @@ void make_parts(char *dev, int cnt)
 	int odig = odig; /* quiet gcc -Os unitialized warning */
 	int i;
 	int nlen = strlen(dev) + 20;
-	char *name = malloc(nlen);
+	char *name;
 	int dig = isdigit(dev[strlen(dev)-1]);
 	char orig[1024];
 	char sym[1024];
@@ -52,6 +52,7 @@ void make_parts(char *dev, int cnt)
 	if (cnt==0) cnt=4;
 	if (lstat(dev, &stb)!= 0)
 		return;
+
 	if (S_ISLNK(stb.st_mode)) {
 		int len = readlink(dev, orig, sizeof(orig));
 		if (len < 0 || len > 1000)
@@ -63,6 +64,7 @@ void make_parts(char *dev, int cnt)
 		minor_num = minor(stb.st_rdev);
 	} else
 		   return;
+	name = malloc(nlen);
 	for (i=1; i <= cnt ; i++) {
 		struct stat stb2;
 		snprintf(name, nlen, "%s%s%d", dev, dig?"p":"", i);
@@ -92,6 +94,7 @@ void make_parts(char *dev, int cnt)
 		if (err == 0 && stat(name, &stb2) == 0)
 			add_dev(name, &stb2, 0, NULL);
 	}
+	free(name);
 }
 
 




More information about the pkg-mdadm-commits mailing list