]> xenbits.xensource.com Git - libvirt.git/commitdiff
rpc: avoid crash on error
authorEric Blake <eblake@redhat.com>
Tue, 2 Aug 2011 19:36:14 +0000 (13:36 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 2 Aug 2011 21:04:36 +0000 (15:04 -0600)
Detected by Coverity.  Freeing the wrong variable results in both
a memory leak and the likelihood of the caller dereferencing through
a freed pointer.

* src/rpc/virnettlscontext.c (virNetTLSSessionNew): Free correct
variable.

src/rpc/virnettlscontext.c

index be082074cb0c62ef4c199b82e81566e740aebdb5..19a9b258fe29e599ba404a4ef8892244999a6670 100644 (file)
@@ -1159,7 +1159,8 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
     virNetTLSSessionPtr sess;
     int err;
 
-    VIR_DEBUG("ctxt=%p hostname=%s isServer=%d", ctxt, NULLSTR(hostname), ctxt->isServer);
+    VIR_DEBUG("ctxt=%p hostname=%s isServer=%d",
+              ctxt, NULLSTR(hostname), ctxt->isServer);
 
     if (VIR_ALLOC(sess) < 0) {
         virReportOOMError();
@@ -1169,7 +1170,7 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
     if (virMutexInit(&sess->lock) < 0) {
         virNetError(VIR_ERR_INTERNAL_ERROR, "%s",
                     _("Failed to initialized mutex"));
-        VIR_FREE(ctxt);
+        VIR_FREE(sess);
         return NULL;
     }