From 9716b459cabcbc412a230ceb975369103ce2addc Mon Sep 17 00:00:00 2001 From: Chris Gunn Date: Mon, 10 Oct 2022 13:36:18 -0700 Subject: Fix memory leak in libvirt_virStreamRecv. The libvirt_virStreamRecv function uses a temporary allocated buffer to receive data before copying the data into a Python byte array. But there are some error paths where this buffer is not freed. This change fixes that memory leak. Signed-off-by: Chris Gunn --- libvirt-override.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libvirt-override.c b/libvirt-override.c index 2a2a7dd..b28f155 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -7926,10 +7926,14 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED, buf[ret > -1 ? ret : 0] = '\0'; DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf)); - if (ret == -2) + if (ret == -2) { + VIR_FREE(buf); return libvirt_intWrap(ret); - if (ret < 0) + } + if (ret < 0) { + VIR_FREE(buf); return VIR_PY_NONE; + } rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret); VIR_FREE(buf); return rv; -- cgit v1.2.1