Free X509_EXTENSIONs

Previously, we would leak these extensions as they are not freed by the
stack. An except from the `sk_TYPE_free` documentation:

    sk_TYPE_free() frees up the sk structure. It does not free up any
    elements of sk. After this call sk is no longer valid.

The fix is to drain the stack and free its elements before freeing the
stack. sk_TYPE_pop_free does this, so we use that instead.

Change-Id: Ie70c302f9dda5af1a7243f163d36e99916ee639c
Signed-off-by: Jimmy Brisson <jimmy.brisson@arm.com>
This commit is contained in:
Jimmy Brisson 2020-07-24 14:31:48 -05:00 committed by Manish Pandey
parent 32269499cc
commit bea8019826
1 changed files with 5 additions and 0 deletions

View File

@ -539,6 +539,11 @@ int main(int argc, char *argv[])
exit(1);
}
for (cert_ext = sk_X509_EXTENSION_pop(sk); cert_ext != NULL;
cert_ext = sk_X509_EXTENSION_pop(sk)) {
X509_EXTENSION_free(cert_ext);
}
sk_X509_EXTENSION_free(sk);
}