Fix fstab memory leak

When reading the fstab config file fails, fstab memory is not freed.
When fstab structure is no longer needed, only half of it is freed.

Free fstab memory in all cases (error or when it is no longer needed).

Change-Id: Ib0758a5aaa69505285bf64143632986a2dbbdccb
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
This commit is contained in:
Irina Tirdea 2013-09-18 23:00:54 +03:00 committed by Elliott Hughes
parent 810ff69609
commit d431b8d7f1

View file

@ -222,7 +222,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path)
char *line = NULL;
const char *delim = " \t";
char *save_ptr, *p;
struct fstab *fstab;
struct fstab *fstab = NULL;
struct fstab_rec *recs;
char *key_loc;
long long part_length;
@ -345,7 +345,10 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path)
return fstab;
err:
fclose(fstab_file);
free(line);
if (fstab)
fs_mgr_free_fstab(fstab);
return NULL;
}
@ -361,7 +364,6 @@ void fs_mgr_free_fstab(struct fstab *fstab)
free(fstab->recs[i].fs_options);
free(fstab->recs[i].key_loc);
free(fstab->recs[i].label);
i++;
}
/* Free the fstab_recs array created by calloc(3) */