]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
rpc: Plug memory leak on virNetClientSendInternal() error path
authorAlex Jia <ajia@redhat.com>
Wed, 30 Nov 2011 05:57:09 +0000 (13:57 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 30 Nov 2011 23:23:18 +0000 (16:23 -0700)
Detected by Coverity. Leak introduced in commit 673adba.

Two separate bugs here:
1. call was not freed on all error paths
2. virCondDestroy was called even if virCondInit failed

Signed-off-by: Alex Jia <ajia@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/rpc/virnetclient.c

index a738129623c884f1425117b5a4269da2a7b8f0ad..5165c8d49dbd7909abb025e3f5a022ef68f54620 100644 (file)
@@ -1708,7 +1708,7 @@ static int virNetClientSendInternal(virNetClientPtr client,
     if (!client->sock || client->wantClose) {
         virNetError(VIR_ERR_INTERNAL_ERROR, "%s",
                     _("client socket is closed"));
-        goto unlock;
+        goto cleanup;
     }
 
     if (virCondInit(&call->cond) < 0) {
@@ -1729,16 +1729,16 @@ static int virNetClientSendInternal(virNetClientPtr client,
 
     ret = virNetClientIO(client, call);
 
-cleanup:
     /* If partially sent, then the call is still on the dispatch queue */
     if (ret == 1) {
         call->haveThread = false;
     } else {
         ignore_value(virCondDestroy(&call->cond));
-        VIR_FREE(call);
     }
 
-unlock:
+cleanup:
+    if (ret != 1)
+        VIR_FREE(call);
     virNetClientUnlock(client);
     return ret;
 }