1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-08-30 05:49:28 +03:00

Add missing test for failed pool allocation

Add test for NULL from dm_poll_create.
Reorder dm_pool_destroy() before file close and add label out:.
Avoid leaking file descriptor if the allocation fails.
This commit is contained in:
Zdenek Kabelac
2010-11-30 22:23:35 +00:00
parent a8d4cd68eb
commit 14caa4a2d0
2 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.78 - Version 2.02.78 -
==================================== ====================================
Add missing test for failed pool allocation in write_config_node().
Replace snprintf with dm_snprintf in clvmd-command.c. Replace snprintf with dm_snprintf in clvmd-command.c.
Check reallocated buffer for NULL before use in clvmd do_command(). Check reallocated buffer for NULL before use in clvmd do_command().
Fix memory leak when VG allocation policy in metadata is invalid. Fix memory leak when VG allocation policy in metadata is invalid.

View File

@ -511,7 +511,8 @@ int write_config_node(const struct config_node *cn, putline_fn putline, void *ba
{ {
struct output_line outline; struct output_line outline;
outline.fp = NULL; outline.fp = NULL;
outline.mem = dm_pool_create("config_line", 1024); if (!(outline.mem = dm_pool_create("config_line", 1024)))
return_0;
outline.putline = putline; outline.putline = putline;
outline.putline_baton = baton; outline.putline_baton = baton;
if (!_write_config(cn, 0, &outline, 0)) { if (!_write_config(cn, 0, &outline, 0)) {
@ -538,7 +539,10 @@ int write_config_file(struct config_tree *cft, const char *file,
return 0; return 0;
} }
outline.mem = dm_pool_create("config_line", 1024); if (!(outline.mem = dm_pool_create("config_line", 1024))) {
r = 0;
goto_out;
}
log_verbose("Dumping configuration to %s", file); log_verbose("Dumping configuration to %s", file);
if (!argc) { if (!argc) {
@ -559,12 +563,14 @@ int write_config_file(struct config_tree *cft, const char *file,
argv++; argv++;
} }
dm_pool_destroy(outline.mem);
out:
if (outline.fp && lvm_fclose(outline.fp, file)) { if (outline.fp && lvm_fclose(outline.fp, file)) {
stack; stack;
r = 0; r = 0;
} }
dm_pool_destroy(outline.mem);
return r; return r;
} }