diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2016-03-07 10:32:41 +0100 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-03-07 10:43:50 +0100 |
commit | d03b1779b4e2edaec221e2c29d3384d4c86052cd (patch) | |
tree | c8a49832cc5c9ececcb2f4a9e02fefe38335f177 | |
parent | 7b15ca5c9ac3645b8d714014f89dbcd6731b2b04 (diff) | |
download | lvm2-d03b1779b4e2edaec221e2c29d3384d4c86052cd.tar.gz |
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.
-rw-r--r-- | lib/format_text/export.c | 12 | ||||
-rw-r--r-- | lib/format_text/text_export.h | 1 |
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/format_text/export.c b/lib/format_text/export.c index c4c7b381e..90fb0443a 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -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: diff --git a/lib/format_text/text_export.h b/lib/format_text/text_export.h index 33c136bb3..377ee9367 100644 --- a/lib/format_text/text_export.h +++ b/lib/format_text/text_export.h @@ -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; |