]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Free some malloced memory that wasn't being freed.
authorNeilBrown <neilb@suse.de>
Thu, 22 Oct 2009 00:00:56 +0000 (11:00 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 22 Oct 2009 00:00:56 +0000 (11:00 +1100)
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@suse.de>
Detail.c
Manage.c
mdopen.c

index e41ad1bb12bea8632b3a0daa5cef394379f50e83..544cfdb5c03ef0a4188db467217b7655b25e42dd 100644 (file)
--- 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;
index 3aa09bcba241caba52b989abd6804de9e65a056e..84eb3abc16ae37e7934460f7aa66a9af1dd08e9d 100644 (file)
--- 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);
index ed53d6f3392237bd4df343ea0c6afbbd1fab3430..21baf5da8bb5532e2eff3f494598758f2624e7c6 100644 (file)
--- 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);
 }