From ed246fbb7972a7ec04a10107f1e745c6d85e923d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 2 Aug 2011 13:36:14 -0600 Subject: [PATCH] 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. --- src/rpc/virnettlscontext.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; }