File 464889ff-rpc-aquire-ref-dispatch.patch of Package libvirt.8367

commit 464889fff8174f560316c998f9f38814c9a57771
Author: Daniel P. Berrangé <berrange@redhat.com>
Date:   Tue Mar 6 16:07:35 2018 +0000

    rpc: push ref acquisition into RPC dispatch function
    
    There's no reason why the virNetServerClientDispatchRead method needs to
    acquire an extra reference on the "client" object. An extra reference is
    only needed if the registered dispatch callback is going to keep hold of
    the "client" for work in the background. Thus we can push reference
    acquisition into virNetServerDispatchNewMessage.
    
    Reviewed-by: John Ferlan <jferlan@redhat.com>
    Reviewed-by: Jim Fehlig <jfehlig@suse.com>
    Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Index: libvirt-4.0.0/src/rpc/virnetserver.c
===================================================================
--- libvirt-4.0.0.orig/src/rpc/virnetserver.c
+++ libvirt-4.0.0/src/rpc/virnetserver.c
@@ -217,9 +217,11 @@ static int virNetServerDispatchNewMessag
             priority = virNetServerProgramGetPriority(prog, msg->header.proc);
         }
 
+        virObjectRef(client);
         ret = virThreadPoolSendJob(srv->workers, priority, job);
 
         if (ret < 0) {
+            virObjectUnref(client);
             VIR_FREE(job);
             virObjectUnref(prog);
         }
Index: libvirt-4.0.0/src/rpc/virnetserverclient.c
===================================================================
--- libvirt-4.0.0.orig/src/rpc/virnetserverclient.c
+++ libvirt-4.0.0/src/rpc/virnetserverclient.c
@@ -1320,12 +1320,10 @@ static void virNetServerClientDispatchRe
 
         /* Send off to for normal dispatch to workers */
         if (msg) {
-            virObjectRef(client);
             if (!client->dispatchFunc ||
                 client->dispatchFunc(client, msg, client->dispatchOpaque) < 0) {
                 virNetMessageFree(msg);
                 client->wantClose = true;
-                virObjectUnref(client);
                 return;
             }
         }