apps/cmp.c: Fix memory leaks in handle_opt_geninfo() found by Coverity
[oweals/openssl.git] / apps / cmp.c
index 05fae77d38baa62c1acdceb1bbdc0da5fefc156a..638005b4fcbc317746c0d4114cd6b4bb0b296de4 100644 (file)
@@ -2042,12 +2042,11 @@ static int handle_opt_geninfo(OSSL_CMP_CTX *ctx)
         return 0;
     }
 
-    aint = ASN1_INTEGER_new();
-    if (aint == NULL || !ASN1_INTEGER_set(aint, value))
+    if ((aint = ASN1_INTEGER_new()) == NULL)
         goto oom;
 
     val = ASN1_TYPE_new();
-    if (val == NULL) {
+    if (!ASN1_INTEGER_set(aint, value) || val == NULL) {
         ASN1_INTEGER_free(aint);
         goto oom;
     }
@@ -2065,6 +2064,7 @@ static int handle_opt_geninfo(OSSL_CMP_CTX *ctx)
     return 1;
 
  oom:
+    ASN1_OBJECT_free(type);
     CMP_err("out of memory");
     return 0;
 }