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@suse.de>
This commit is contained in:
NeilBrown 2009-10-22 11:00:56 +11:00
parent 1799c9e8f8
commit 0eb26465c0
3 changed files with 8 additions and 2 deletions

View File

@ -541,6 +541,7 @@ This is pretty boring
1, avail, avail_disks))
rv = 2;
free(disks);
out:
close(fd);
return rv;

View File

@ -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);

View File

@ -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);
}