[PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc

Mahmoud Mandour posted 8 patches 4 years, 11 months ago
Maintainers: Warner Losh <imp@bsdimp.com>, Stefan Hajnoczi <stefanha@redhat.com>, Max Filippov <jcmvbkbc@gmail.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Kyle Evans <kevans@freebsd.org>, Gerd Hoffmann <kraxel@redhat.com>
[PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc
Posted by Mahmoud Mandour 4 years, 11 months ago
Replaced a malloc() call and its respective free() with
GLib's g_try_malloc() and g_free() calls.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
 tools/virtiofsd/fuse_opt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virtiofsd/fuse_opt.c b/tools/virtiofsd/fuse_opt.c
index f0ab8d22f4..9d371448e9 100644
--- a/tools/virtiofsd/fuse_opt.c
+++ b/tools/virtiofsd/fuse_opt.c
@@ -272,7 +272,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx,
     }
 
     param = ctx->argv[ctx->argctr];
-    newarg = malloc(sep + strlen(param) + 1);
+    newarg = g_try_malloc(sep + strlen(param) + 1);
     if (!newarg) {
         return alloc_failed();
     }
@@ -280,7 +280,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx,
     memcpy(newarg, arg, sep);
     strcpy(newarg + sep, param);
     res = process_opt(ctx, opt, sep, newarg, iso);
-    free(newarg);
+    g_free(newarg);
 
     return res;
 }
-- 
2.25.1


Re: [PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc
Posted by Stefan Hajnoczi 4 years, 11 months ago
On Sun, Mar 14, 2021 at 05:23:23AM +0200, Mahmoud Mandour wrote:
> Replaced a malloc() call and its respective free() with
> GLib's g_try_malloc() and g_free() calls.
> 
> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
> ---
>  tools/virtiofsd/fuse_opt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>