From 0eb62708a7cbd4e42d2ccb0b5d0c78ba93dd732e Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Sun, 3 Feb 2013 09:52:02 -0500 Subject: [PATCH] virnettlscontexttest: Resolve memory leak found by Valgrind testTLSDerEncode() will allocate memory for der.data, it wasn't VIR_FREE()'d. also don't initialized der to use static buffer. --- tests/virnettlscontexttest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index e0a2788b47..3df8a709ad 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -160,7 +160,7 @@ testTLSGenerateCert(struct testTLSCertReq *req) static char buffer[1024*1024]; size_t size = sizeof(buffer); char serial[5] = { 1, 2, 3, 4, 0 }; - gnutls_datum_t der = { (unsigned char *)buffer, size }; + gnutls_datum_t der; time_t start = time(NULL) + (60*60*req->start_offset); time_t expire = time(NULL) + (60*60*(req->expire_offset ? req->expire_offset : 24)); @@ -294,9 +294,11 @@ testTLSGenerateCert(struct testTLSCertReq *req) der.size, req->basicConstraintsCritical)) < 0) { VIR_WARN("Failed to set certificate basic constraints %s", gnutls_strerror(err)); + VIR_FREE(der.data); abort(); } asn1_delete_structure(&ext); + VIR_FREE(der.data); } /* @@ -320,9 +322,11 @@ testTLSGenerateCert(struct testTLSCertReq *req) der.size, req->keyUsageCritical)) < 0) { VIR_WARN("Failed to set certificate key usage %s", gnutls_strerror(err)); + VIR_FREE(der.data); abort(); } asn1_delete_structure(&ext); + VIR_FREE(der.data); } /* @@ -350,9 +354,11 @@ testTLSGenerateCert(struct testTLSCertReq *req) der.size, req->keyPurposeCritical)) < 0) { VIR_WARN("Failed to set certificate key purpose %s", gnutls_strerror(err)); + VIR_FREE(der.data); abort(); } asn1_delete_structure(&ext); + VIR_FREE(der.data); } /* -- GitLab