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

Re: [libvirt] [PATCH 7/3] rpc: avoid crash on error



On 08/02/2011 03:38 PM, Eric Blake wrote:
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 |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index be08207..eeffe54 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -1164,17 +1164,17 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
      if (VIR_ALLOC(sess)<  0) {
          virReportOOMError();
          return NULL;
      }

      if (virMutexInit(&sess->lock)<  0) {
          virNetError(VIR_ERR_INTERNAL_ERROR, "%s",
                      _("Failed to initialized mutex"));
-        VIR_FREE(ctxt);
+        VIR_FREE(sess);
          return NULL;


You could just as well replace this with a goto error, but ACK anyway.


      }

      sess->refs = 1;
      if (hostname&&
          !(sess->hostname = strdup(hostname))) {
          virReportOOMError();
          goto error;


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