From 0a0761746f670e34335826ea90b3fffe93e519fe Mon Sep 17 00:00:00 2001 From: olszomal Date: Fri, 8 Mar 2024 13:26:40 +0100 Subject: [PATCH] Fixed memory corruption --- osslsigncode.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/osslsigncode.c b/osslsigncode.c index 6dd3934..cc9a05b 100644 --- a/osslsigncode.c +++ b/osslsigncode.c @@ -4645,13 +4645,24 @@ skip_signing: err_cleanup: if (outdata) { + BIO *head = hash; + int outdata_in_hash = 0; + + while (head) { + BIO *tail = BIO_pop(head); + + if (head == outdata) + outdata_in_hash = 1; + BIO_free(head); + head = tail; + } + if (!outdata_in_hash) + BIO_free_all(outdata); + if (options.outfile) { /* unlink outfile */ remove_file(options.outfile); } - if (hash) - BIO_free_all(hash); - BIO_free(outdata); } if (ctx && ctx->format->ctx_cleanup) { ctx->format->ctx_cleanup(ctx);