@@ -1127,7 +1127,7 @@ int test_x509_ReqCertFromX509_skid_max(void)
11271127 defined(WOLFSSL_CERT_REQ ) && !defined(NO_BIO ) && defined(HAVE_ECC ) && \
11281128 defined(USE_CERT_BUFFERS_256 ) && \
11291129 (defined(OPENSSL_EXTRA ) || defined(OPENSSL_ALL ))
1130- X509 * req = NULL ;
1130+ X509_REQ * req = NULL ;
11311131 X509_NAME * name = NULL ;
11321132 EVP_PKEY * priv = NULL ;
11331133 BIO * bio = NULL ;
@@ -1137,6 +1137,7 @@ int test_x509_ReqCertFromX509_skid_max(void)
11371137 STACK_OF (X509_EXTENSION )* exts = NULL ;
11381138 const unsigned char * keyPtr = ecc_clikey_der_256 ;
11391139 unsigned char skid_bytes [CTC_MAX_SKID_SIZE ];
1140+ int pushed = 0 ;
11401141 int i ;
11411142
11421143 for (i = 0 ; i < CTC_MAX_SKID_SIZE ; i ++ ) {
@@ -1160,9 +1161,14 @@ int test_x509_ReqCertFromX509_skid_max(void)
11601161 ExpectNotNull (skid_ext = X509_EXTENSION_create_by_OBJ (NULL , skid_oid , 0 ,
11611162 skid_data ));
11621163 ExpectNotNull (exts = sk_X509_EXTENSION_new_null ());
1163- ExpectIntEQ (sk_X509_EXTENSION_push (exts , skid_ext ), 1 );
1164- if (EXPECT_FAIL ()) {
1165- X509_EXTENSION_free (skid_ext );
1164+ /* Snapshot the push result so cleanup is decided by *this* call rather
1165+ * than by any earlier expectation failure that may have set EXPECT_FAIL. */
1166+ if (skid_ext != NULL && exts != NULL ) {
1167+ pushed = sk_X509_EXTENSION_push (exts , skid_ext );
1168+ }
1169+ ExpectIntEQ (pushed , 1 );
1170+ if (pushed == 1 ) {
1171+ skid_ext = NULL ; /* ownership transferred to exts */
11661172 }
11671173 ExpectIntEQ (X509_REQ_add_extensions (req , exts ), 1 );
11681174
@@ -1175,6 +1181,9 @@ int test_x509_ReqCertFromX509_skid_max(void)
11751181
11761182 BIO_free (bio );
11771183 sk_X509_EXTENSION_pop_free (exts , X509_EXTENSION_free );
1184+ /* Free skid_ext only if it was never successfully pushed (ownership
1185+ * remained with us); otherwise pop_free() above already freed it. */
1186+ X509_EXTENSION_free (skid_ext );
11781187 ASN1_OCTET_STRING_free (skid_data );
11791188 ASN1_OBJECT_free (skid_oid );
11801189 EVP_PKEY_free (priv );
0 commit comments