diff mbox

virtio-gpu: call cleanup mapping function in resource destroy

Message ID 1480386565-10077-1-git-send-email-liq3ea@gmail.com
State New
Headers show

Commit Message

Li Qiang Nov. 29, 2016, 2:29 a.m. UTC
If the guest destroy the resource before detach banking, the 'iov'
and 'addrs' field in resource is not freed thus leading memory
leak issue. This patch avoid this.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 hw/display/virtio-gpu.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Marc-André Lureau Nov. 29, 2016, 4:58 a.m. UTC | #1
On Tue, Nov 29, 2016 at 6:29 AM Li Qiang <liq3ea@gmail.com> wrote:

> If the guest destroy the resource before detach banking, the 'iov'
> and 'addrs' field in resource is not freed thus leading memory
> leak issue. This patch avoid this.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
>


Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


---
>  hw/display/virtio-gpu.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index 60bce94..98dadf2 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -28,6 +28,8 @@
>  static struct virtio_gpu_simple_resource*
>  virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
>
> +static void virtio_gpu_cleanup_mapping(struct virtio_gpu_simple_resource
> *res);
> +
>  #ifdef CONFIG_VIRGL
>  #include <virglrenderer.h>
>  #define VIRGL(_g, _virgl, _simple, ...)                     \
> @@ -358,6 +360,7 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g,
>                                          struct virtio_gpu_simple_resource
> *res)
>  {
>      pixman_image_unref(res->image);
> +    virtio_gpu_cleanup_mapping(res);
>      QTAILQ_REMOVE(&g->reslist, res, next);
>      g_free(res);
>  }
> --
> 1.8.3.1
>
> --
Marc-André Lureau
Li Qiang Dec. 13, 2016, 10:31 a.m. UTC | #2
Ping!

2016-11-29 10:29 GMT+08:00 Li Qiang <liq3ea@gmail.com>:

> If the guest destroy the resource before detach banking, the 'iov'
> and 'addrs' field in resource is not freed thus leading memory
> leak issue. This patch avoid this.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  hw/display/virtio-gpu.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index 60bce94..98dadf2 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -28,6 +28,8 @@
>  static struct virtio_gpu_simple_resource*
>  virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
>
> +static void virtio_gpu_cleanup_mapping(struct virtio_gpu_simple_resource
> *res);
> +
>  #ifdef CONFIG_VIRGL
>  #include <virglrenderer.h>
>  #define VIRGL(_g, _virgl, _simple, ...)                     \
> @@ -358,6 +360,7 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g,
>                                          struct virtio_gpu_simple_resource
> *res)
>  {
>      pixman_image_unref(res->image);
> +    virtio_gpu_cleanup_mapping(res);
>      QTAILQ_REMOVE(&g->reslist, res, next);
>      g_free(res);
>  }
> --
> 1.8.3.1
>
>
diff mbox

Patch

diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 60bce94..98dadf2 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -28,6 +28,8 @@ 
 static struct virtio_gpu_simple_resource*
 virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
 
+static void virtio_gpu_cleanup_mapping(struct virtio_gpu_simple_resource *res);
+
 #ifdef CONFIG_VIRGL
 #include <virglrenderer.h>
 #define VIRGL(_g, _virgl, _simple, ...)                     \
@@ -358,6 +360,7 @@  static void virtio_gpu_resource_destroy(VirtIOGPU *g,
                                         struct virtio_gpu_simple_resource *res)
 {
     pixman_image_unref(res->image);
+    virtio_gpu_cleanup_mapping(res);
     QTAILQ_REMOVE(&g->reslist, res, next);
     g_free(res);
 }