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 66f9383..2c0b7f3 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 d8ed15b..9c0d190 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1184,12 +1184,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 673fb8d..c3a2e59 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 89a2ebf..d7406fc 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);
--
2.7.4