All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] 9pfs: free the private data memory in device unrealize
@ 2016-11-12  8:13 Li Qiang
  2016-11-12 14:08 ` Greg Kurz
  0 siblings, 1 reply; 2+ messages in thread
From: Li Qiang @ 2016-11-12  8:13 UTC (permalink / raw)
  To: groug, qemu-devel; +Cc: Li Qiang

From: Li Qiang <liqiang6-s@360.cn>

When the 9pfs use 'handle'/'proxy' as the backend driver it
will allocate a private data memory. But this memory is not freed in
the unrealize function thus leading a memory leak issue. This patch
avoid this.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
 hw/9pfs/9p.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index aea7e9d..6524b13 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3532,6 +3532,7 @@ void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
 {
     g_free(s->ctx.fs_root);
     g_free(s->tag);
+    g_free(s->ctx.private);
 }
 
 typedef struct VirtfsCoResetData {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] 9pfs: free the private data memory in device unrealize
  2016-11-12  8:13 [Qemu-devel] [PATCH] 9pfs: free the private data memory in device unrealize Li Qiang
@ 2016-11-12 14:08 ` Greg Kurz
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kurz @ 2016-11-12 14:08 UTC (permalink / raw)
  To: Li Qiang; +Cc: qemu-devel, Li Qiang

Hi Li,

On Sat, 12 Nov 2016 00:13:56 -0800
Li Qiang <liq3ea@gmail.com> wrote:

> From: Li Qiang <liqiang6-s@360.cn>
> 
> When the 9pfs use 'handle'/'proxy' as the backend driver it
> will allocate a private data memory. But this memory is not freed in
> the unrealize function thus leading a memory leak issue. This patch
> avoid this.
> 
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
>  hw/9pfs/9p.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index aea7e9d..6524b13 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -3532,6 +3532,7 @@ void v9fs_device_unrealize_common(V9fsState *s, Error **errp)
>  {
>      g_free(s->ctx.fs_root);
>      g_free(s->tag);
> +    g_free(s->ctx.private);

This is wrong: we cannot do any assumptions on the private data in the core
code. It can only be used in the backend code. You need to add a .cleanup
operation to the FileOperations structure and implement it in the handle and
proxy backends.

Also, it appears that there's more to be done than just freeing the private
data itself:
- handle needs to close mountfd
- proxy needs to close sockfd and free some allocated iov_base

Cheers.

--
Greg

>  }
>  
>  typedef struct VirtfsCoResetData {

	

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-12 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-12  8:13 [Qemu-devel] [PATCH] 9pfs: free the private data memory in device unrealize Li Qiang
2016-11-12 14:08 ` Greg Kurz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.