btrfs-progs: fix memory leak on error path

dev_scans and t_scans should be freed on malloc error.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Eryu Guan 2015-10-19 19:37:57 +08:00 committed by David Sterba
parent 529f5c5854
commit 140592187b

View File

@ -846,11 +846,16 @@ static int scan_devices(struct recover_control *rc)
if (!dev_scans)
return -ENOMEM;
t_scans = (pthread_t *)malloc(sizeof(pthread_t) * devnr);
if (!t_scans)
if (!t_scans) {
free(dev_scans);
return -ENOMEM;
}
t_rets = (long *)malloc(sizeof(long) * devnr);
if (!t_rets)
if (!t_rets) {
free(dev_scans);
free(t_scans);
return -ENOMEM;
}
list_for_each_entry(dev, &rc->fs_devices->devices, dev_list) {
fd = open(dev->name, O_RDONLY);