From 4c8be54cc430bbebd41fd7c452ff4ff9e8ff2bd5 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 13 Apr 2021 14:26:15 +0900 Subject: [PATCH] tools: Fix memory leaks. * tools/gpgsplit.c (write_part): Free BLOB on error. -- GnuPG-bug-id: 5393 Signed-off-by: Jakub Jelen --- tools/gpgsplit.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/gpgsplit.c b/tools/gpgsplit.c index 7257b63e1..cc7bf8ef5 100644 --- a/tools/gpgsplit.c +++ b/tools/gpgsplit.c @@ -582,7 +582,10 @@ write_part (FILE *fpin, unsigned long pktlen, { c = getc (fpin); if (c == EOF) - goto read_error; + { + xfree (blob); + goto read_error; + } blob[i] = c; } len = public_key_length (blob, pktlen); @@ -594,18 +597,27 @@ write_part (FILE *fpin, unsigned long pktlen, if ( (hdr[0] & 0x40) ) { if (write_new_header (fpout, pkttype, len)) - goto write_error; + { + xfree (blob); + goto write_error; + } } else { if (write_old_header (fpout, pkttype, len)) - goto write_error; + { + xfree (blob); + goto write_error; + } } for (i=0; i < len; i++) { if ( putc (blob[i], fpout) == EOF ) - goto write_error; + { + xfree (blob); + goto write_error; + } } goto ready;