Re: [libvirt PATCH 5/6] src: don't use VIR_FREE on an object allocation

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

 



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é <berrange@xxxxxxxxxx>
---
  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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux