[Qemu-devel] [PATCH 28/31] 9pfs: replace g_malloc()+memcpy() with g_memdup()

Marc-André Lureau posted 31 patches 8 years, 7 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 28/31] 9pfs: replace g_malloc()+memcpy() with g_memdup()
Posted by Marc-André Lureau 8 years, 7 months ago
I found these pattern via grepping the source tree. I don't have a
coccinelle script for it!

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/9pfs/9p-synth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index 4b6d4e6a3f..df0a8de08a 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -494,8 +494,7 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
     }
 out:
     /* Copy the node pointer to fid */
-    target->data = g_malloc(sizeof(void *));
-    memcpy(target->data, &node, sizeof(void *));
+    target->data = g_memdup(&node, sizeof(void *));
     target->size = sizeof(void *);
     return 0;
 }
-- 
2.13.1.395.gf7b71de06


Re: [Qemu-devel] [PATCH 28/31] 9pfs: replace g_malloc()+memcpy() with g_memdup()
Posted by Greg Kurz 8 years, 7 months ago
On Thu, 22 Jun 2017 14:42:01 +0200
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:

> I found these pattern via grepping the source tree. I don't have a
> coccinelle script for it!
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---

Thanks! Applied to my 9p-next branch at:

https://github.com/gkurz/qemu/commits/9p-next

>  hw/9pfs/9p-synth.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> index 4b6d4e6a3f..df0a8de08a 100644
> --- a/hw/9pfs/9p-synth.c
> +++ b/hw/9pfs/9p-synth.c
> @@ -494,8 +494,7 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
>      }
>  out:
>      /* Copy the node pointer to fid */
> -    target->data = g_malloc(sizeof(void *));
> -    memcpy(target->data, &node, sizeof(void *));
> +    target->data = g_memdup(&node, sizeof(void *));
>      target->size = sizeof(void *);
>      return 0;
>  }