From: Benny Baumann Date: Thu, 1 Oct 2020 23:06:12 +0000 (+0200) Subject: Avoid memory leak of parent on allocation failure for child structure X-Git-Tag: OpenSSL_1_1_1i~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7455f247e6f9d621fa79ae3af1588df23078fb11;p=thirdparty%2Fopenssl.git Avoid memory leak of parent on allocation failure for child structure Reviewed-by: Ben Kaduk Reviewed-by: Dmitry Belyavskiy Reviewed-by: Richard Levitte Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/13055) (cherry picked from commit a21db568bf3d0ab4194fd3e0917ee982f1fc8bfd) --- diff --git a/apps/cms.c b/apps/cms.c index 15edd67dbef..60691f14686 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -545,9 +545,11 @@ int cms_main(int argc, char **argv) if (key_param == NULL || key_param->idx != keyidx) { cms_key_param *nparam; nparam = app_malloc(sizeof(*nparam), "key param buffer"); - nparam->idx = keyidx; - if ((nparam->param = sk_OPENSSL_STRING_new_null()) == NULL) + if ((nparam->param = sk_OPENSSL_STRING_new_null()) == NULL) { + OPENSSL_free(nparam); goto end; + } + nparam->idx = keyidx; nparam->next = NULL; if (key_first == NULL) key_first = nparam;