Skip to contentSkip to conversation

virtio-gpu-3d: fix memory leak in resource attach backing

PATCH In review Li Qiang 2 participants 3 messages Dec 29, 2016 – Dec 30, 2016

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 virtio-gpu-3d: fix memory leak in resource attach backing

If the virgl_renderer_resource_attach_iov function fails the 'res_iovs' will be leaked. Add check of the return value to free the 'res_iovs' when failing.

---
 hw/display/virtio-gpu-3d.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +5 -2
index 23f39de..07b3691 100644
@@ -291,8 +291,11 @@ static void virgl_resource_attach_backing(VirtIOGPU *g,
         return;
     }
 
-    virgl_renderer_resource_attach_iov(att_rb.resource_id,
-                                       res_iovs, att_rb.nr_entries);
+    ret = virgl_renderer_resource_attach_iov(att_rb.resource_id,
+                                             res_iovs, att_rb.nr_entries);
+
+    if (ret != 0)
+        virtio_gpu_cleanup_mapping_iov(res_iovs, att_rb.nr_entries);
 }
 
 static void virgl_resource_detach_backing(VirtIOGPU *g,
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

----- Original Message -----

Quoted 5 lines

If the virgl_renderer_resource_attach_iov function fails the 'res_iovs' will be leaked. Add check of the return value to free the 'res_iovs' when failing.

Interestingly, in vrend_renderer_resource_attach_iov(), if the resource has already been attached, it returns 0 too, which will also leak. I guess the fix is it return an error in this case.

Quoted 28 lines
---
 hw/display/virtio-gpu-3d.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +5 -2
index 23f39de..07b3691 100644
@@ -291,8 +291,11 @@ static void virgl_resource_attach_backing(VirtIOGPU *g,
         return;
     }
 
-    virgl_renderer_resource_attach_iov(att_rb.resource_id,
-                                       res_iovs, att_rb.nr_entries);
+    ret = virgl_renderer_resource_attach_iov(att_rb.resource_id,
+                                             res_iovs, att_rb.nr_entries);
+
+    if (ret != 0)
+        virtio_gpu_cleanup_mapping_iov(res_iovs, att_rb.nr_entries);
 
 
 }

static void virgl_resource_detach_backing(VirtIOGPU *g,
--
1.8.3.1

author
#2 lore raw

2016-12-29 21:56 GMT+08:00 Marc-André Lureau <[email protected]>:

Quoted 7 lines

Hi

----- Original Message -----

Quoted 4 lines

If the virgl_renderer_resource_attach_iov function fails the 'res_iovs' will be leaked. Add check of the return value to free the 'res_iovs' when failing.

Quoted 9 lines
Quoted 1 line

Interestingly, in vrend_renderer_resource_attach_iov(), if the resource has already been attached, it returns 0 too, which will also leak. I guess the fix is it return an error in this case.

Right, actually I have write a patch for this here:

https://cgit.freedesktop.org/virglrenderer/commit/?id=40b0e7813325b08077b6f541b3989edb2d86d837

But the patch just return 0 if the 'iov' exist.

Quoted 31 lines

hw/display/virtio-gpu-3d.c static void virgl_resource_attach_backing(VirtIOGPU

Quoted 9 lines
---
 hw/display/virtio-gpu-3d.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-3d.c +0 -0
index 23f39de..07b3691 100644
@@ -291,8 +291,11 @@ static void virgl_resource_attach_backing(VirtIOGPU

*g,

hw/display/virtio-gpu-3d.c static void virgl_resource_attach_backing(VirtIOGPU *g,

Quoted 7 lines
hw/display/virtio-gpu-3d.c +2 -2
         return;
     }
 
-    virgl_renderer_resource_attach_iov(att_rb.resource_id,
-                                       res_iovs, att_rb.nr_entries);
+    ret = virgl_renderer_resource_attach_iov(att_rb.resource_id,
+                                             res_iovs,

att_rb.nr_entries);

Quoted 12 lines
hw/display/virtio-gpu-3d.c +3 -0
+
+    if (ret != 0)
+        virtio_gpu_cleanup_mapping_iov(res_iovs, att_rb.nr_entries);
 
 
 }

static void virgl_resource_detach_backing(VirtIOGPU *g,
--
1.8.3.1