Simplify X509_STORE_free()
authortb <tb@openbsd.org>
Fri, 22 Mar 2024 06:24:54 +0000 (06:24 +0000)
committertb <tb@openbsd.org>
Fri, 22 Mar 2024 06:24:54 +0000 (06:24 +0000)
This had an inlined version of sk_pop_free(). We can just call it the
right way.

ok jsing

lib/libcrypto/x509/x509_lu.c

index 56fb439..0edcfca 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509_lu.c,v 1.64 2024/03/02 10:57:03 tb Exp $ */
+/* $OpenBSD: x509_lu.c,v 1.65 2024/03/22 06:24:54 tb Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -63,6 +63,7 @@
 #include <openssl/lhash.h>
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
+
 #include "x509_local.h"
 
 static X509_LOOKUP *
@@ -221,22 +222,13 @@ x509_object_dup(const X509_OBJECT *obj)
 void
 X509_STORE_free(X509_STORE *store)
 {
-       STACK_OF(X509_LOOKUP) *sk;
-       X509_LOOKUP *lu;
-       int i;
-
        if (store == NULL)
                return;
 
        if (CRYPTO_add(&store->references, -1, CRYPTO_LOCK_X509_STORE) > 0)
                return;
 
-       sk = store->get_cert_methods;
-       for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) {
-               lu = sk_X509_LOOKUP_value(sk, i);
-               X509_LOOKUP_free(lu);
-       }
-       sk_X509_LOOKUP_free(sk);
+       sk_X509_LOOKUP_pop_free(store->get_cert_methods, X509_LOOKUP_free);
        sk_X509_OBJECT_pop_free(store->objs, X509_OBJECT_free);
 
        CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, store, &store->ex_data);