1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

coverity: fix possible resource leak in _print_historical_lv function

The code in _print_historical_lv function works with temporary
"descendants_buffer" that is allocated and freed within this
function.

When printing text out, we used "outf" macro which called
"out_text" fn and it checked return value and if failed,
the macro called "return_0" automatically. But since we
use the temporary buffer, if any of the out_text calls
fails, we need to deallocate this buffer properly - that's
the "goto_out", otherwise we'll be leaking memory.

So add new "outfgo" helper macro which does the same as "outf",
but it calls "goto_out" instead of "return_0" so we can jump
to a cleanup hook at the end.
This commit is contained in:
Peter Rajnoha 2016-03-07 10:32:41 +01:00
parent 7b15ca5c9a
commit d03b1779b4
2 changed files with 7 additions and 6 deletions

View File

@ -854,10 +854,10 @@ static int _print_historical_lv(struct formatter *f, struct historical_logical_v
goto_out;
outnl(f);
outf(f, "%s {", hlv->name);
outfgo(f, "%s {", hlv->name);
_inc_indent(f);
outf(f, "id = \"%s\"", buffer);
outfgo(f, "id = \"%s\"", buffer);
if (!_print_timestamp(f, "creation_time", hlv->timestamp, buffer, sizeof(buffer)))
goto_out;
@ -867,16 +867,16 @@ static int _print_historical_lv(struct formatter *f, struct historical_logical_v
if (hlv->indirect_origin) {
if (hlv->indirect_origin->is_historical)
outf(f, "origin = \"%s%s\"", HISTORICAL_LV_PREFIX, hlv->indirect_origin->historical->name);
outfgo(f, "origin = \"%s%s\"", HISTORICAL_LV_PREFIX, hlv->indirect_origin->historical->name);
else
outf(f, "origin = \"%s\"", hlv->indirect_origin->live->name);
outfgo(f, "origin = \"%s\"", hlv->indirect_origin->live->name);
}
if (descendants_buffer)
outf(f, "descendants = %s", descendants_buffer);
outfgo(f, "descendants = %s", descendants_buffer);
_dec_indent(f);
outf(f, "}");
outfgo(f, "}");
r = 1;
out:

View File

@ -20,6 +20,7 @@
#define outhint(args...) do {if (!out_hint(args)) return_0;} while (0)
#define outfc(args...) do {if (!out_text_with_comment(args)) return_0;} while (0)
#define outf(args...) do {if (!out_text(args)) return_0;} while (0)
#define outfgo(args...) do {if (!out_text(args)) goto_out;} while (0)
#define outnl(f) do {if (!out_newline(f)) return_0;} while (0)
struct formatter;