summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Gunn <chrisgun@microsoft.com>2022-10-10 13:36:18 -0700
committerChris Gunn <chrisgun@microsoft.com>2022-10-10 13:36:18 -0700
commit9716b459cabcbc412a230ceb975369103ce2addc (patch)
treef7a178985f1fef9865e7ab4cb576dc651aabc507
parentd9b9517cc381c1717ae2b74f461f372b5866af5e (diff)
downloadlibvirt-python-9716b459cabcbc412a230ceb975369103ce2addc.tar.gz
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 <chrisgun@microsoft.com>
-rw-r--r--libvirt-override.c8
1 files 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;