diff --git a/src/x509.c b/src/x509.c index 349832a..74b0a3d 100644 --- a/src/x509.c +++ b/src/x509.c @@ -176,7 +176,7 @@ finish: X509* x509_get_root_ca(const char *file, STACK_OF(X509) **stack_ca) { int x509_cnt = 0; - X509 *x = NULL, *end = NULL; + X509 *x = NULL, *node = NULL, *root = NULL; BIO *bio = NULL; STACK_OF(X509) *stack_x509 = NULL; @@ -199,13 +199,13 @@ X509* x509_get_root_ca(const char *file, STACK_OF(X509) **stack_ca) if (0 == X509_NAME_cmp(X509_get_issuer_name(x), X509_get_subject_name(x))) { /*This is root ca**/ + root = x; continue; - X509_free(x); }; /*This is last ca*/ if (x509_get_last_ca(file, x) == 0) { - end = x; + node = x; continue; } sk_X509_push(stack_x509, x); @@ -214,10 +214,13 @@ X509* x509_get_root_ca(const char *file, STACK_OF(X509) **stack_ca) } if (x509_cnt >= 1) *stack_ca = stack_x509; - + if (node != NULL) + X509_free(root); + else + node = root; BIO_free (bio); finish: - return end; + return node; } static X509 *