summaryrefslogtreecommitdiff
path: root/doc/examples/ex-verify.c
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2021-03-15 11:03:44 +0100
committerDaiki Ueno <ueno@gnu.org>2021-03-15 11:03:44 +0100
commit1ff33c12aa1a8dc96f3e35cf690b0cafff00c151 (patch)
tree13e6155d999a311f291e481c271c38cd30970c9d /doc/examples/ex-verify.c
parentdba8ab0de551d164683c54dfde9c32599d3ed10a (diff)
downloadgnutls-1ff33c12aa1a8dc96f3e35cf690b0cafff00c151.tar.gz
examples: avoid memory leak in ex-verify
Signed-off-by: Daiki Ueno <ueno@gnu.org>
Diffstat (limited to 'doc/examples/ex-verify.c')
-rw-r--r--doc/examples/ex-verify.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/doc/examples/ex-verify.c b/doc/examples/ex-verify.c
index 623198793b..a4f6ebec9e 100644
--- a/doc/examples/ex-verify.c
+++ b/doc/examples/ex-verify.c
@@ -54,7 +54,7 @@ verify_certificate_chain(const char *hostname,
CHECK(gnutls_x509_trust_list_add_crls(tlist, crl_list, crl_list_size,
GNUTLS_TL_VERIFY_CRL, 0));
- cert = malloc(sizeof(*cert) * cert_chain_length);
+ cert = gnutls_calloc(cert_chain_length, sizeof(*cert));
assert(cert != NULL);
/* Import all the certificates in the chain to
@@ -104,6 +104,11 @@ verify_certificate_chain(const char *hostname,
hostname);
}
+ for (i = 0; i < cert_chain_length; i++) {
+ gnutls_x509_crt_deinit(cert[i]);
+ }
+ gnutls_free(cert);
+
gnutls_x509_trust_list_deinit(tlist, 1);
return;