]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid memory leak of parent on allocation failure for child structure
authorBenny Baumann <BenBE@geshi.org>
Thu, 1 Oct 2020 23:06:12 +0000 (01:06 +0200)
committerPauli <paul.dale@oracle.com>
Tue, 6 Oct 2020 22:58:25 +0000 (08:58 +1000)
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13055)

(cherry picked from commit a21db568bf3d0ab4194fd3e0917ee982f1fc8bfd)

apps/cms.c

index 15edd67dbefd5ac39608fa6fc35b409484604cc1..60691f14686533883d97628878515c13edb1f133 100644 (file)
@@ -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;