1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

Fix memory leak when VG allocation policy in metadata is invalid.

Ignore unrecognised allocation policy found in metadata instead of aborting.
Fix another missing vg_release() in _vg_read_by_vgid.
This commit is contained in:
Alasdair Kergon 2010-11-29 18:35:37 +00:00
parent 2e3be4f3fd
commit 1415afcdba
4 changed files with 37 additions and 28 deletions

View File

@ -1,16 +1,22 @@
Version 2.02.78 - Version 2.02.78 -
==================================== ====================================
Fix memory leak in outf macro error path of _print_vg/lv/pvs/segment(). Fix memory leak when VG allocation policy in metadata is invalid.
Fix missing reset of vg pointer after vg_release() in _vg_read_by_vgid(). Ignore unrecognised allocation policy found in metadata instead of aborting.
Fix test for empty system_dir string in _init_backup(). Factor out tag printing into _out_tags and avoid leaking string buffer.
Certain lvconvert invocations are now required to be done in two steps. Remove some unused variables & assignments.
Fix missing context desctruction in err path of lvm1 fallback in lvm2_main(). Add missing vg_release calls in _vg_read_by_vgid.
Fix memory leak in error path of parse_loop_device_name() from dmsetup. Still to fix: LCK_CACHE/CLUSTER_VG printing/FIXME
Fix missing dlclose in _init_formats() error path from init_format call. Fix test for no system_dir in _init_backup().
Fix missing fclose for _umount() in dmeventd snapshot plugin. Disallow lvconvert ops that both allocate & free supplied PEs in a single cmd.
Fix out-of-scope variable usage in process_each_lv(). Fix liblvm seg_size to give bytes not sectors.
Fix dm_task_destroy(NULL) call in _node_clear_table() error path. Add functions to look up LV/PV by name/uuid to liblvm.
Fix resource leak in _rm_blks(). Free cmd_context if fallback to LVM1 fails in lvm2_main().
Free device name buffer in dmsetup parse_loop_device_name() error paths.
Close format lib if init_format_fn fails in _init_formats().
Don't leave /proc/mounts open after dmeventd snapshot event processing.
Fix out-of-scope arg_vgnames use in process_each_lv().
Remove incorrect dm_task_destroy(NULL) from _node_clear_table() error path.
Add missing closedir in _rm_blks after removing stray LVM1 VG files.
Suppress 'No PV label' message when removing several PVs without mdas. Suppress 'No PV label' message when removing several PVs without mdas.
Fix default /etc/lvm permissions to be 0755. (2.02.66) Fix default /etc/lvm permissions to be 0755. (2.02.66)

View File

@ -1,5 +1,6 @@
Version 1.02.59 - Version 1.02.59 -
==================================== ====================================
Remove superfluous checks for NULL before calling dm_free.
Version 1.02.58 - 22nd November 2010 Version 1.02.58 - 22nd November 2010
==================================== ====================================

View File

@ -529,8 +529,10 @@ static int _read_lvnames(struct format_instance *fid __attribute__((unused)),
} }
lv->alloc = get_alloc_from_string(cv->v.str); lv->alloc = get_alloc_from_string(cv->v.str);
if (lv->alloc == ALLOC_INVALID) if (lv->alloc == ALLOC_INVALID) {
return_0; log_warn("WARNING: Ignoring unrecognised allocation policy %s for LV %s", cv->v.str, lv->name);
lv->alloc = ALLOC_INHERIT;
}
} }
if (!_read_int32(lvn, "read_ahead", &lv->read_ahead)) if (!_read_int32(lvn, "read_ahead", &lv->read_ahead))
@ -660,7 +662,8 @@ static struct volume_group *_read_vg(struct format_instance *fid,
return_NULL; return_NULL;
/* skip any top-level values */ /* skip any top-level values */
for (vgn = cft->root; (vgn && vgn->v); vgn = vgn->sib) ; for (vgn = cft->root; (vgn && vgn->v); vgn = vgn->sib)
;
if (!vgn) { if (!vgn) {
log_error("Couldn't find volume group in file."); log_error("Couldn't find volume group in file.");
@ -738,12 +741,14 @@ static struct volume_group *_read_vg(struct format_instance *fid,
struct config_value *cv = cn->v; struct config_value *cv = cn->v;
if (!cv || !cv->v.str) { if (!cv || !cv->v.str) {
log_error("allocation_policy must be a string."); log_error("allocation_policy must be a string.");
return 0; goto bad;
} }
vg->alloc = get_alloc_from_string(cv->v.str); vg->alloc = get_alloc_from_string(cv->v.str);
if (vg->alloc == ALLOC_INVALID) if (vg->alloc == ALLOC_INVALID) {
return_0; log_warn("WARNING: Ignoring unrecognised allocation policy %s for VG %s", cv->v.str, vg->name);
vg->alloc = ALLOC_NORMAL;
}
} }
if (!_read_uint32(vgn, "metadata_copies", &vg->mda_copies)) { if (!_read_uint32(vgn, "metadata_copies", &vg->mda_copies)) {

View File

@ -3086,6 +3086,7 @@ void vg_release(struct volume_group *vg)
vg->name); vg->name);
dm_pool_destroy(vg->vgmem); dm_pool_destroy(vg->vgmem);
vg->vgmem = NULL;
} }
/* This is only called by lv_from_lvid, which is only called from /* This is only called by lv_from_lvid, which is only called from
@ -3098,7 +3099,7 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
{ {
const char *vgname; const char *vgname;
struct dm_list *vgnames; struct dm_list *vgnames;
struct volume_group *vg = NULL; struct volume_group *vg;
struct lvmcache_vginfo *vginfo; struct lvmcache_vginfo *vginfo;
struct str_list *strl; struct str_list *strl;
int consistent = 0; int consistent = 0;
@ -3109,20 +3110,17 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
if ((vg = _vg_read(cmd, NULL, vgid, 1, if ((vg = _vg_read(cmd, NULL, vgid, 1,
&consistent, precommitted)) && &consistent, precommitted)) &&
!strncmp((char *)vg->id.uuid, vgid, ID_LEN)) { !strncmp((char *)vg->id.uuid, vgid, ID_LEN)) {
if (!consistent)
if (!consistent) {
log_error("Volume group %s metadata is " log_error("Volume group %s metadata is "
"inconsistent", vg->name); "inconsistent", vg->name);
}
return vg; return vg;
} }
vg_release(vg); vg_release(vg);
vg = NULL; /* reset so memlock goto out is safe */
} }
/* Mustn't scan if memory locked: ensure cache gets pre-populated! */ /* Mustn't scan if memory locked: ensure cache gets pre-populated! */
if (memlock()) if (memlock())
goto out; return_NULL;
/* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */ /* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */
/* FIXME Disabled vgrenames while active for now because we aren't /* FIXME Disabled vgrenames while active for now because we aren't
@ -3132,7 +3130,7 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
lvmcache_label_scan(cmd, 2); lvmcache_label_scan(cmd, 2);
if (!(vgnames = get_vgnames(cmd, 0))) { if (!(vgnames = get_vgnames(cmd, 0))) {
log_error("vg_read_by_vgid: get_vgnames failed"); log_error("vg_read_by_vgid: get_vgnames failed");
goto out; return NULL;
} }
dm_list_iterate_items(strl, vgnames) { dm_list_iterate_items(strl, vgnames) {
@ -3143,18 +3141,17 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
if ((vg = _vg_read(cmd, vgname, vgid, 1, &consistent, if ((vg = _vg_read(cmd, vgname, vgid, 1, &consistent,
precommitted)) && precommitted)) &&
!strncmp((char *)vg->id.uuid, vgid, ID_LEN)) { !strncmp((char *)vg->id.uuid, vgid, ID_LEN)) {
if (!consistent) { if (!consistent) {
log_error("Volume group %s metadata is " log_error("Volume group %s metadata is "
"inconsistent", vgname); "inconsistent", vgname);
goto out; vg_release(vg);
return NULL;
} }
return vg; return vg;
} }
vg_release(vg);
} }
out:
vg_release(vg);
return NULL; return NULL;
} }