From: Eric Blake Date: Tue, 2 Aug 2011 19:36:14 +0000 (-0600) Subject: rpc: avoid crash on error X-Git-Tag: v0.9.4~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed246fbb7972a7ec04a10107f1e745c6d85e923d;p=thirdparty%2Flibvirt.git rpc: avoid crash on error 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. --- diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index be082074cb..19a9b258fe 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -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; }