1. There are some places which didn't free map as
discovered by coverity.
CID 289661 (#1 of 1): Resource leak (RESOURCE_LEAK)12. leaked_storage: Variable mapl going out of scope leaks the storage it points to.
CID 289619 (#3 of 3): Resource leak (RESOURCE_LEAK)63. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289618 (#1 of 1): Resource leak (RESOURCE_LEAK)26. leaked_storage: Variable map going out of scope leaks the storage it points to.
CID 289607 (#1 of 1): Resource leak (RESOURCE_LEAK)41. leaked_storage: Variable map going out of scope leaks the storage it points to.
2. If we call map_by_* inside a loop, then map_free
should be called in the same loop, and it is better
to set map to NULL after free.
3. And map_unlock is always called with map_lock,
if we don't call map_remove before map_unlock,
then the memory (allocated by map_lock -> map_read
-> map_add -> xmalloc) could be leaked. So we
need to free it in map_unlock as well.
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
if (rv == 1 && !pre_exist)
ioctl(mdfd, STOP_ARRAY, NULL);
free(devices);
- map_unlock(&map);
out:
+ map_unlock(&map);
if (rv == 0) {
wait_for(chosen_name, mdfd);
close(mdfd);
if (st->ss->export_detail_super)
st->ss->export_detail_super(st);
+ map_free(map);
} else {
struct map_ent *mp, *map = NULL;
char nbuf[64];
print_escape(mp->path+8);
putchar('\n');
}
+ map_free(map);
}
if (sra) {
struct mdinfo *mdi;
sysfs_free(sra);
}
}
+ map_free(mapl);
return rv;
}
assemble_container_content(st, mdfd, ra, c,
chosen_name, &result);
+ map_free(map);
+ map = NULL;
close(mdfd);
}
if (c->export && result) {
close(sfd);
}
domain_free(domains);
+ map_free(map);
return 0;
}
}
d->next = rv;
rv = d;
+ map_free(map);
+ map = NULL;
}
free_mdstat(mdstat);
- map_free(map);
return rv;
}
unlink(mapname[2]);
fclose(lf);
}
+ if (*melp)
+ map_free(*melp);
lf = NULL;
}
else
rv |= WaitClean(name, c->verbose);
put_md_name(name);
+ map_free(map);
+ map = NULL;
}
}
free_mdstat(ms);