All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@6wind.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, pbonzini@redhat.com,
	claudio.fontana@huawei.com, jani.kokkonen@huawei.com,
	eblake@redhat.com, cam@cs.ualberta.ca, armbru@redhat.com,
	stefanha@gmail.com, arei.gonglei@huawei.com
Subject: [PATCH v4 09/14] contrib/ivshmem-*: switch to g_malloc0/g_free
Date: Tue,  2 Sep 2014 17:25:27 +0200	[thread overview]
Message-ID: <1409671532-12706-10-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1409671532-12706-1-git-send-email-david.marchand@6wind.com>

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 contrib/ivshmem-client/ivshmem-client.c |    9 ++-------
 contrib/ivshmem-server/ivshmem-server.c |   12 ++----------
 2 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-client/ivshmem-client.c
index 2ba40a7..a08f4d9 100644
--- a/contrib/ivshmem-client/ivshmem-client.c
+++ b/contrib/ivshmem-client/ivshmem-client.c
@@ -82,7 +82,7 @@ free_peer(IvshmemClient *client, IvshmemClientPeer *peer)
         close(peer->vectors[vector]);
     }
 
-    free(peer);
+    g_free(peer);
 }
 
 /* handle message coming from server (new peer, new vectors) */
@@ -116,12 +116,7 @@ handle_server_msg(IvshmemClient *client)
 
     /* new peer */
     if (peer == NULL) {
-        peer = malloc(sizeof(*peer));
-        if (peer == NULL) {
-            debug_log(client, "cannot allocate new peer\n");
-            return -1;
-        }
-        memset(peer, 0, sizeof(*peer));
+        peer = g_malloc0(sizeof(*peer));
         peer->id = peer_id;
         peer->vectors_count = 0;
         QTAILQ_INSERT_TAIL(&client->peer_list, peer, next);
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index e0d4d1d..15d468c 100644
--- a/contrib/ivshmem-server/ivshmem-server.c
+++ b/contrib/ivshmem-server/ivshmem-server.c
@@ -90,7 +90,7 @@ free_peer(IvshmemServer *server, IvshmemServerPeer *peer)
         close(peer->vectors[vector]);
     }
 
-    free(peer);
+    g_free(peer);
 }
 
 /* send the peer id and the shm_fd just after a new client connection */
@@ -138,15 +138,7 @@ handle_new_conn(IvshmemServer *server)
     debug_log(server, "accept()=%d\n", newfd);
 
     /* allocate new structure for this peer */
-    peer = malloc(sizeof(*peer));
-    if (peer == NULL) {
-        debug_log(server, "cannot allocate new peer\n");
-        close(newfd);
-        return -1;
-    }
-
-    /* initialize the peer struct, one eventfd per vector */
-    memset(peer, 0, sizeof(*peer));
+    peer = g_malloc0(sizeof(*peer));
     peer->sock_fd = newfd;
 
     /* get an unused peer id */
-- 
1.7.10.4


WARNING: multiple messages have this Message-ID (diff)
From: David Marchand <david.marchand@6wind.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, stefanha@gmail.com,
	claudio.fontana@huawei.com, armbru@redhat.com,
	arei.gonglei@huawei.com, pbonzini@redhat.com,
	jani.kokkonen@huawei.com, cam@cs.ualberta.ca
Subject: [Qemu-devel] [PATCH v4 09/14] contrib/ivshmem-*: switch to g_malloc0/g_free
Date: Tue,  2 Sep 2014 17:25:27 +0200	[thread overview]
Message-ID: <1409671532-12706-10-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1409671532-12706-1-git-send-email-david.marchand@6wind.com>

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 contrib/ivshmem-client/ivshmem-client.c |    9 ++-------
 contrib/ivshmem-server/ivshmem-server.c |   12 ++----------
 2 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-client/ivshmem-client.c
index 2ba40a7..a08f4d9 100644
--- a/contrib/ivshmem-client/ivshmem-client.c
+++ b/contrib/ivshmem-client/ivshmem-client.c
@@ -82,7 +82,7 @@ free_peer(IvshmemClient *client, IvshmemClientPeer *peer)
         close(peer->vectors[vector]);
     }
 
-    free(peer);
+    g_free(peer);
 }
 
 /* handle message coming from server (new peer, new vectors) */
@@ -116,12 +116,7 @@ handle_server_msg(IvshmemClient *client)
 
     /* new peer */
     if (peer == NULL) {
-        peer = malloc(sizeof(*peer));
-        if (peer == NULL) {
-            debug_log(client, "cannot allocate new peer\n");
-            return -1;
-        }
-        memset(peer, 0, sizeof(*peer));
+        peer = g_malloc0(sizeof(*peer));
         peer->id = peer_id;
         peer->vectors_count = 0;
         QTAILQ_INSERT_TAIL(&client->peer_list, peer, next);
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index e0d4d1d..15d468c 100644
--- a/contrib/ivshmem-server/ivshmem-server.c
+++ b/contrib/ivshmem-server/ivshmem-server.c
@@ -90,7 +90,7 @@ free_peer(IvshmemServer *server, IvshmemServerPeer *peer)
         close(peer->vectors[vector]);
     }
 
-    free(peer);
+    g_free(peer);
 }
 
 /* send the peer id and the shm_fd just after a new client connection */
@@ -138,15 +138,7 @@ handle_new_conn(IvshmemServer *server)
     debug_log(server, "accept()=%d\n", newfd);
 
     /* allocate new structure for this peer */
-    peer = malloc(sizeof(*peer));
-    if (peer == NULL) {
-        debug_log(server, "cannot allocate new peer\n");
-        close(newfd);
-        return -1;
-    }
-
-    /* initialize the peer struct, one eventfd per vector */
-    memset(peer, 0, sizeof(*peer));
+    peer = g_malloc0(sizeof(*peer));
     peer->sock_fd = newfd;
 
     /* get an unused peer id */
-- 
1.7.10.4

  parent reply	other threads:[~2014-09-02 15:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-02 15:25 [PATCH v4 00/14] ivshmem: update documentation, add client/server tools David Marchand
2014-09-02 15:25 ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 01/14] contrib: add ivshmem client and server David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 20:20   ` Eric Blake
2014-09-02 20:20     ` [Qemu-devel] " Eric Blake
2014-09-02 15:25 ` [PATCH v4 02/14] docs: update ivshmem device spec David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 20:24   ` Eric Blake
2014-09-02 20:24     ` [Qemu-devel] " Eric Blake
2014-09-02 15:25 ` [PATCH v4 03/14] contrib/ivshmem-*: comply with QEMU coding style David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 04/14] contrib/ivshmem-*: reuse qemu/queue.h David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 05/14] contrib/ivshmem-*: switch to QEMU headers David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 20:28   ` Eric Blake
2014-09-02 20:28     ` [Qemu-devel] " Eric Blake
2014-09-02 15:25 ` [PATCH v4 06/14] contrib/ivshmem-server: set client sockets as non blocking David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 07/14] contrib/ivshmem-*: add missing const and static attrs David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 08/14] contrib/ivshmem-*: plug client and server in QEMU top Makefile David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` David Marchand [this message]
2014-09-02 15:25   ` [Qemu-devel] [PATCH v4 09/14] contrib/ivshmem-*: switch to g_malloc0/g_free David Marchand
2014-09-02 15:25 ` [PATCH v4 10/14] contrib/ivshmem-server: fix mem leak on error David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 11/14] contrib/ivshmem-*: rework error handling David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 12/14] contrib/ivshmem-*: various fixes David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 13/14] contrib/ivshmem-server: align server default parameter values David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 15:25 ` [PATCH v4 14/14] ivshmem: add check on protocol version in QEMU David Marchand
2014-09-02 15:25   ` [Qemu-devel] " David Marchand
2014-09-02 20:31 ` [PATCH v4 00/14] ivshmem: update documentation, add client/server tools Eric Blake
2014-09-02 20:31   ` [Qemu-devel] " Eric Blake
2014-09-03 13:01   ` David Marchand
2014-09-03 13:01     ` [Qemu-devel] " David Marchand
2014-09-03 14:47     ` Eric Blake
2014-09-03 14:47       ` [Qemu-devel] " Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409671532-12706-10-git-send-email-david.marchand@6wind.com \
    --to=david.marchand@6wind.com \
    --cc=arei.gonglei@huawei.com \
    --cc=armbru@redhat.com \
    --cc=cam@cs.ualberta.ca \
    --cc=claudio.fontana@huawei.com \
    --cc=eblake@redhat.com \
    --cc=jani.kokkonen@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.