On 5/19/20 7:41 PM, Daniel P. Berrangé wrote:
Memory allocated using g_object_new must never be released using
VIR_FREE/g_free because g_object_new uses a special allocation
strategy internally.

Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
  src/rpc/virnettlscontext.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 02c17124a1..ced0cbdcd8 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -750,12 +750,9 @@ static virNetTLSContextPtr virNetTLSContextNew(const char 
*cacert,
      return ctxt;
error:
+    virObjectUnref(ctxt);
      if (isServer)
          gnutls_dh_params_deinit(ctxt->dhParams);
-    if (ctxt->x509cred)
-        gnutls_certificate_free_credentials(ctxt->x509cred);
-    VIR_FREE(ctxt->priority);
-    VIR_FREE(ctxt);

The unref call needs to go exactly here, where you remove these lines, because at the point we jump onto the error label, @ctxt has exactly one reference. And if you decrease it, the object is freed and the subsequent call to gnutls_whatever() would deref invalid pointer.

Michal

Reply via email to