Assemble: re-arrange freeing of 'tst' in load_devices().

When we return in error, we need to free(tst), and ->free_super(tst);
Sometimes we didn't.

Also the final ->free_super(tst) should be followed by free(tst)
but wasn't.

Move that file free forward in the code a bit as we will want to use
the tst there in the next patch.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2014-02-25 14:59:12 +11:00
parent df842e69a3
commit 9ee314dab9
1 changed files with 11 additions and 8 deletions

View File

@ -572,6 +572,7 @@ static int load_devices(struct devs *devices, char *devmap,
for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) { for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) {
char *devname = tmpdev->devname; char *devname = tmpdev->devname;
struct stat stb; struct stat stb;
struct supertype *tst;
int i; int i;
if (tmpdev->used != 1) if (tmpdev->used != 1)
@ -582,7 +583,6 @@ static int load_devices(struct devs *devices, char *devmap,
int dfd; int dfd;
/* prepare useful information in info structures */ /* prepare useful information in info structures */
struct stat stb2; struct stat stb2;
struct supertype *tst;
int err; int err;
fstat(mdfd, &stb2); fstat(mdfd, &stb2);
@ -611,6 +611,8 @@ static int load_devices(struct devs *devices, char *devmap,
close(mdfd); close(mdfd);
free(devices); free(devices);
free(devmap); free(devmap);
tst->ss->free_super(tst);
free(tst);
*stp = st; *stp = st;
return -1; return -1;
} }
@ -660,15 +662,13 @@ static int load_devices(struct devs *devices, char *devmap,
else else
bitmap_done = 1; bitmap_done = 1;
} }
tst->ss->free_super(tst);
} else } else
#endif #endif
{ {
struct supertype *tst = dup_super(st); int dfd = dev_open(devname,
int dfd; tmpdev->disposition == 'I'
dfd = dev_open(devname, ? O_RDWR : (O_RDWR|O_EXCL));
tmpdev->disposition == 'I' tst = dup_super(st);
? O_RDWR : (O_RDWR|O_EXCL));
if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
pr_err("cannot re-read metadata from %s - aborting\n", pr_err("cannot re-read metadata from %s - aborting\n",
@ -678,11 +678,12 @@ static int load_devices(struct devs *devices, char *devmap,
close(mdfd); close(mdfd);
free(devices); free(devices);
free(devmap); free(devmap);
tst->ss->free_super(tst);
free(tst);
*stp = st; *stp = st;
return -1; return -1;
} }
tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks); tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks);
tst->ss->free_super(tst);
close(dfd); close(dfd);
} }
@ -705,6 +706,8 @@ static int load_devices(struct devs *devices, char *devmap,
> devices[most_recent].i.events) > devices[most_recent].i.events)
most_recent = devcnt; most_recent = devcnt;
} }
tst->ss->free_super(tst);
free(tst);
if (content->array.level == LEVEL_MULTIPATH) if (content->array.level == LEVEL_MULTIPATH)
/* with multipath, the raid_disk from the superblock is meaningless */ /* with multipath, the raid_disk from the superblock is meaningless */