From b6238738ea9cad9e41ed94ce2f45bd8be74ef306 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 27 Apr 2016 18:02:22 -0400 Subject: [PATCH] rpc: use virNetMessageClearPayload in client This removes the opencoded payload freeing in the client, to use the shared virNetMessageClearPayload call. Two changes: - ClearPayload sets nfds=0, which fixes a potential crash if an error path called virNetMessageFree/Clear on the message after fds was free'd - We drop the inner loop VIR_FORCE_CLOSE... this may mean fds are kept open a little bit longer if the call is blocking but in practice I don't think it will have any effect --- src/libvirt_remote.syms | 1 + src/rpc/virnetclient.c | 6 +----- src/rpc/virnetmessage.c | 2 +- src/rpc/virnetmessage.h | 2 ++ 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index afcb2b7556..6b098b4bea 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -79,6 +79,7 @@ virNetDaemonUpdateServices; # rpc/virnetmessage.h virNetMessageClear; +virNetMessageClearPayload; virNetMessageDecodeHeader; virNetMessageDecodeLength; virNetMessageDecodeNumFDs; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 26b02fa944..3d599903ec 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1194,12 +1194,8 @@ virNetClientIOWriteMessage(virNetClientPtr client, if (rv == 0) /* Blocking */ return 0; thecall->msg->donefds++; - VIR_FORCE_CLOSE(thecall->msg->fds[i]); } - thecall->msg->donefds = 0; - thecall->msg->bufferOffset = thecall->msg->bufferLength = 0; - VIR_FREE(thecall->msg->fds); - VIR_FREE(thecall->msg->buffer); + virNetMessageClearPayload(thecall->msg); if (thecall->expectReply) thecall->mode = VIR_NET_CLIENT_MODE_WAIT_RX; else diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 673fb8d000..c3a2e595c1 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -49,7 +49,7 @@ virNetMessagePtr virNetMessageNew(bool tracked) } -static void +void virNetMessageClearPayload(virNetMessagePtr msg) { size_t i; diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h index 89a2ebf716..d7406fcd24 100644 --- a/src/rpc/virnetmessage.h +++ b/src/rpc/virnetmessage.h @@ -54,6 +54,8 @@ struct _virNetMessage { virNetMessagePtr virNetMessageNew(bool tracked); +void virNetMessageClearPayload(virNetMessagePtr msg); + void virNetMessageClear(virNetMessagePtr); void virNetMessageFree(virNetMessagePtr msg);