* [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs
@ 2014-08-19 8:30 zhanghailiang
2014-08-20 13:23 ` Benoît Canet
2014-08-20 14:57 ` Michael Tokarev
0 siblings, 2 replies; 5+ messages in thread
From: zhanghailiang @ 2014-08-19 8:30 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, luonengjun, mjt, peter.huangpeng, zhanghailiang
Here we don't check the return value of malloc() which may fail.
Use the g_new() instead, which will abort the program when
there is not enough memory.
Also, use g_strdup instead of strdup and remove the unnecessary
strdup function.
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
slirp/misc.c | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)
diff --git a/slirp/misc.c b/slirp/misc.c
index b8eb74c..6543dc7 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -54,11 +54,11 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
}
tmp_ptr = *ex_ptr;
- *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
+ *ex_ptr = g_new(struct ex_list, 1);
(*ex_ptr)->ex_fport = port;
(*ex_ptr)->ex_addr = addr;
(*ex_ptr)->ex_pty = do_pty;
- (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
+ (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec);
(*ex_ptr)->ex_next = tmp_ptr;
return 0;
}
@@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
bptr++;
c = *bptr;
*bptr++ = (char)0;
- argv[i++] = strdup(curarg);
+ argv[i++] = g_strdup(curarg);
} while (c);
argv[i] = NULL;
@@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
}
#endif
-#ifndef HAVE_STRDUP
-char *
-strdup(str)
- const char *str;
-{
- char *bptr;
-
- bptr = (char *)malloc(strlen(str)+1);
- strcpy(bptr, str);
-
- return bptr;
-}
-#endif
-
void slirp_connection_info(Slirp *slirp, Monitor *mon)
{
const char * const tcpstates[] = {
--
1.7.12.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs
2014-08-19 8:30 [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs zhanghailiang
@ 2014-08-20 13:23 ` Benoît Canet
2014-08-20 14:57 ` Michael Tokarev
1 sibling, 0 replies; 5+ messages in thread
From: Benoît Canet @ 2014-08-20 13:23 UTC (permalink / raw)
To: zhanghailiang; +Cc: qemu-trivial, mjt, luonengjun, qemu-devel, peter.huangpeng
The Tuesday 19 Aug 2014 à 16:30:17 (+0800), zhanghailiang wrote :
> Here we don't check the return value of malloc() which may fail.
> Use the g_new() instead, which will abort the program when
> there is not enough memory.
>
> Also, use g_strdup instead of strdup and remove the unnecessary
> strdup function.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> slirp/misc.c | 20 +++-----------------
> 1 file changed, 3 insertions(+), 17 deletions(-)
>
> diff --git a/slirp/misc.c b/slirp/misc.c
> index b8eb74c..6543dc7 100644
> --- a/slirp/misc.c
> +++ b/slirp/misc.c
> @@ -54,11 +54,11 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
> }
>
> tmp_ptr = *ex_ptr;
> - *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
> + *ex_ptr = g_new(struct ex_list, 1);
> (*ex_ptr)->ex_fport = port;
> (*ex_ptr)->ex_addr = addr;
> (*ex_ptr)->ex_pty = do_pty;
> - (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
> + (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec);
> (*ex_ptr)->ex_next = tmp_ptr;
> return 0;
> }
> @@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
> bptr++;
> c = *bptr;
> *bptr++ = (char)0;
> - argv[i++] = strdup(curarg);
> + argv[i++] = g_strdup(curarg);
> } while (c);
>
> argv[i] = NULL;
> @@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
> }
> #endif
>
> -#ifndef HAVE_STRDUP
> -char *
> -strdup(str)
> - const char *str;
> -{
> - char *bptr;
> -
> - bptr = (char *)malloc(strlen(str)+1);
> - strcpy(bptr, str);
> -
> - return bptr;
> -}
> -#endif
> -
> void slirp_connection_info(Slirp *slirp, Monitor *mon)
> {
> const char * const tcpstates[] = {
> --
> 1.7.12.4
>
>
>
Reviewed-by: Benoît Canet <benoit.canet@nodalink.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs
2014-08-19 8:30 [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs zhanghailiang
2014-08-20 13:23 ` Benoît Canet
@ 2014-08-20 14:57 ` Michael Tokarev
2014-08-20 15:03 ` Michael Tokarev
1 sibling, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2014-08-20 14:57 UTC (permalink / raw)
To: zhanghailiang, qemu-devel; +Cc: qemu-trivial, luonengjun, peter.huangpeng
19.08.2014 12:30, zhanghailiang wrote:
> Here we don't check the return value of malloc() which may fail.
> Use the g_new() instead, which will abort the program when
> there is not enough memory.
>
> Also, use g_strdup instead of strdup and remove the unnecessary
> strdup function.
I also will remove the HAVE_STRDUP define from slirp_config.h --
it is no longer needed there.
Applied to -trivial (with the above addition), thank you!
/mjt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs
2014-08-20 14:57 ` Michael Tokarev
@ 2014-08-20 15:03 ` Michael Tokarev
2014-08-21 0:42 ` zhanghailiang
0 siblings, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2014-08-20 15:03 UTC (permalink / raw)
To: zhanghailiang, qemu-devel; +Cc: qemu-trivial, luonengjun, peter.huangpeng
20.08.2014 18:57, Michael Tokarev пишет:
> 19.08.2014 12:30, zhanghailiang wrote:
>> Here we don't check the return value of malloc() which may fail.
>> Use the g_new() instead, which will abort the program when
>> there is not enough memory.
>>
>> Also, use g_strdup instead of strdup and remove the unnecessary
>> strdup function.
>
> I also will remove the HAVE_STRDUP define from slirp_config.h --
> it is no longer needed there.
>
> Applied to -trivial (with the above addition), thank you!
..And with removal of the corresponding #ifdef HAVE_STRDUP from slirp/misc.h.
/mjt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs
2014-08-20 15:03 ` Michael Tokarev
@ 2014-08-21 0:42 ` zhanghailiang
0 siblings, 0 replies; 5+ messages in thread
From: zhanghailiang @ 2014-08-21 0:42 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-trivial, luonengjun, qemu-devel, peter.huangpeng
On 2014/8/20 23:03, Michael Tokarev wrote:
> 20.08.2014 18:57, Michael Tokarev пишет:
>> 19.08.2014 12:30, zhanghailiang wrote:
>>> Here we don't check the return value of malloc() which may fail.
>>> Use the g_new() instead, which will abort the program when
>>> there is not enough memory.
>>>
>>> Also, use g_strdup instead of strdup and remove the unnecessary
>>> strdup function.
>>
>> I also will remove the HAVE_STRDUP define from slirp_config.h --
>> it is no longer needed there.
>>
>> Applied to -trivial (with the above addition), thank you!
>
> ..And with removal of the corresponding #ifdef HAVE_STRDUP from slirp/misc.h.
>
> /mjt
>
>
OK! Thanks.
zhanghailiang
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-08-21 0:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 8:30 [Qemu-devel] [PATCH v8] slirp/misc: Use the GLib memory allocation APIs zhanghailiang
2014-08-20 13:23 ` Benoît Canet
2014-08-20 14:57 ` Michael Tokarev
2014-08-20 15:03 ` Michael Tokarev
2014-08-21 0:42 ` zhanghailiang
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.