diff mbox series

[36/88] SLIRP: use g_new() family of functions

Message ID 20171006235023.11952-37-f4bug@amsat.org
State New
Headers show
Series use g_new() family of functions | expand

Commit Message

Philippe Mathieu-Daudé Oct. 6, 2017, 11:49 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
[PMD: added net/slirp.c]
---
 net/slirp.c    | 4 ++--
 slirp/slirp.c  | 2 +-
 slirp/socket.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

Samuel Thibault Oct. 8, 2017, 10:20 p.m. UTC | #1
Hello,

Philippe Mathieu-Daudé, on ven. 06 oct. 2017 20:49:31 -0300, wrote:
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -869,7 +869,7 @@ net_init_slirp_configs(const StringList *fwd, int flags)
>      while (fwd) {
>          struct slirp_config_str *config;
>  
> -        config = g_malloc0(sizeof(*config));
> +        config = g_new0(struct slirp_config_str, 1);

It doesn't really seem like an improvement to me in such case: we don't
have overflow issues here, and using sizeof(*config) makes the line
clearly correct, while expliciting the struct behind means we need to
make sure of the coherency.

> diff --git a/slirp/socket.c b/slirp/socket.c
> index cb7b5b608d..2eccb68c2e 100644
> --- a/slirp/socket.c
> +++ b/slirp/socket.c
> @@ -48,7 +48,7 @@ socreate(Slirp *slirp)
>  {
>    struct socket *so;
>  
> -  so = (struct socket *)malloc(sizeof(struct socket));
> +  so = g_new(struct socket, 1);

Similarly, here I'd rather write g_malloc(sizeof(*so));

Samuel
diff mbox series

Patch

diff --git a/net/slirp.c b/net/slirp.c
index 318a26e892..c42e1fd0d0 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -869,7 +869,7 @@  net_init_slirp_configs(const StringList *fwd, int flags)
     while (fwd) {
         struct slirp_config_str *config;
 
-        config = g_malloc0(sizeof(*config));
+        config = g_new0(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), fwd->value->str);
         config->flags = flags;
         config->next = slirp_configs;
@@ -973,7 +973,7 @@  int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     if (QTAILQ_EMPTY(&slirp_stacks)) {
         struct slirp_config_str *config;
 
-        config = g_malloc(sizeof(*config));
+        config = g_new(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), optarg);
         config->flags = SLIRP_CFG_LEGACY;
         config->next = slirp_configs;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 1cb6b07004..9af9179afa 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -288,7 +288,7 @@  Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in6_addr vnameserver6, const char **vdnssearch,
                   void *opaque)
 {
-    Slirp *slirp = g_malloc0(sizeof(Slirp));
+    Slirp *slirp = g_new0(Slirp, 1);
 
     slirp_init_once();
 
diff --git a/slirp/socket.c b/slirp/socket.c
index cb7b5b608d..2eccb68c2e 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -48,7 +48,7 @@  socreate(Slirp *slirp)
 {
   struct socket *so;
 
-  so = (struct socket *)malloc(sizeof(struct socket));
+  so = g_new(struct socket, 1);
   if(so) {
     memset(so, 0, sizeof(struct socket));
     so->so_state = SS_NOFDREF;