[libvirt] [PATCH] rpc: Fix memleak in virNetMessageEncodeHeader

My latest patch for RPC rework (a2c304f6872) introduced a memory leak. virNetMessageEncodeHeader() is calling VIR_ALLOC_N(msg->buffer, ...) despite fact, that msg->buffer isn't VIR_FREE()'d on all paths calling the function. Therefore, rather than injecting free statement switch to VIR_REALLOC_N(). --- src/rpc/virnetmessage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index dc4c212..82d5f8d 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -219,7 +219,7 @@ int virNetMessageEncodeHeader(virNetMessagePtr msg) unsigned int len = 0; msg->bufferLength = VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX; - if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) { + if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) { virReportOOMError(); goto cleanup; } -- 1.7.8.5

On 06/11/2012 06:28 AM, Michal Privoznik wrote:
My latest patch for RPC rework (a2c304f6872) introduced a memory leak. virNetMessageEncodeHeader() is calling VIR_ALLOC_N(msg->buffer, ...) despite fact, that msg->buffer isn't VIR_FREE()'d on all paths calling the function. Therefore, rather than injecting free statement switch to VIR_REALLOC_N(). --- src/rpc/virnetmessage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 11.06.2012 15:20, Eric Blake wrote:
On 06/11/2012 06:28 AM, Michal Privoznik wrote:
My latest patch for RPC rework (a2c304f6872) introduced a memory leak. virNetMessageEncodeHeader() is calling VIR_ALLOC_N(msg->buffer, ...) despite fact, that msg->buffer isn't VIR_FREE()'d on all paths calling the function. Therefore, rather than injecting free statement switch to VIR_REALLOC_N(). --- src/rpc/virnetmessage.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
ACK.
Thanks, pushed. Michal
participants (2)
-
Eric Blake
-
Michal Privoznik