[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 01/13] virnettlscontexttest: Resolve memory leak found by Valgrind



On 2013年02月07日 05:35, John Ferlan wrote:
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 e0a2788..3df8a70 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);
      }

      /*

ACK


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]