yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From c012dc9b501d96a2ff54a8a7a182726043b69aeb Mon Sep 17 00:00:00 2001
902636
From: jmaloy <jmaloy@redhat.com>
902636
Date: Tue, 12 May 2020 21:15:14 +0100
902636
Subject: [PATCH 3/7] Replace remaining malloc/free user with glib
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: jmaloy <jmaloy@redhat.com>
902636
Message-id: <20200512211514.1398384-3-jmaloy@redhat.com>
902636
Patchwork-id: 96413
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 2/2] Replace remaining malloc/free user with glib
902636
Bugzilla: 1749737
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Thomas Huth <thuth@redhat.com>
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
902636
From: Marc-André Lureau <marcandre.lureau@redhat.com>
902636
902636
glib mem functions are already used in various places. Let's not mix
902636
the two, and instead abort on OOM conditions.
902636
902636
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
902636
(cherry picked from libslirp commit 3a494648526be4eb96cba739a816a60e933ffd14)
902636
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
902636
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 slirp/src/sbuf.c     | 21 ++++++---------------
902636
 slirp/src/socket.c   |  2 +-
902636
 slirp/src/tcp_subr.c |  8 ++------
902636
 3 files changed, 9 insertions(+), 22 deletions(-)
902636
902636
diff --git a/slirp/src/sbuf.c b/slirp/src/sbuf.c
902636
index 0569c34..eab87f3 100644
902636
--- a/slirp/src/sbuf.c
902636
+++ b/slirp/src/sbuf.c
902636
@@ -9,7 +9,7 @@ static void sbappendsb(struct sbuf *sb, struct mbuf *m);
902636
 
902636
 void sbfree(struct sbuf *sb)
902636
 {
902636
-    free(sb->sb_data);
902636
+    g_free(sb->sb_data);
902636
 }
902636
 
902636
 bool sbdrop(struct sbuf *sb, int num)
902636
@@ -39,24 +39,15 @@ void sbreserve(struct sbuf *sb, int size)
902636
     if (sb->sb_data) {
902636
         /* Already alloced, realloc if necessary */
902636
         if (sb->sb_datalen != size) {
902636
-            char *new = realloc(sb->sb_data, size);
902636
+            char *new = g_realloc(sb->sb_data, size);
902636
             sb->sb_cc = 0;
902636
-            if (new) {
902636
-                sb->sb_data = sb->sb_wptr = sb->sb_rptr = new;
902636
-                sb->sb_datalen = size;
902636
-            } else {
902636
-                free(sb->sb_data);
902636
-                sb->sb_data = sb->sb_wptr = sb->sb_rptr = NULL;
902636
-                sb->sb_datalen = 0;
902636
-            }
902636
+            sb->sb_data = sb->sb_wptr = sb->sb_rptr = new;
902636
+            sb->sb_datalen = size;
902636
         }
902636
     } else {
902636
-        sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)malloc(size);
902636
+        sb->sb_wptr = sb->sb_rptr = sb->sb_data = g_malloc(size);
902636
         sb->sb_cc = 0;
902636
-        if (sb->sb_wptr)
902636
-            sb->sb_datalen = size;
902636
-        else
902636
-            sb->sb_datalen = 0;
902636
+        sb->sb_datalen = size;
902636
     }
902636
 }
902636
 
902636
diff --git a/slirp/src/socket.c b/slirp/src/socket.c
902636
index 34daffc..ace18bf 100644
902636
--- a/slirp/src/socket.c
902636
+++ b/slirp/src/socket.c
902636
@@ -95,7 +95,7 @@ void sofree(struct socket *so)
902636
         remque(so); /* crashes if so is not in a queue */
902636
 
902636
     if (so->so_tcpcb) {
902636
-        free(so->so_tcpcb);
902636
+        g_free(so->so_tcpcb);
902636
     }
902636
     g_free(so);
902636
 }
902636
diff --git a/slirp/src/tcp_subr.c b/slirp/src/tcp_subr.c
902636
index 26d4ead..4e5a801 100644
902636
--- a/slirp/src/tcp_subr.c
902636
+++ b/slirp/src/tcp_subr.c
902636
@@ -255,11 +255,7 @@ struct tcpcb *tcp_newtcpcb(struct socket *so)
902636
 {
902636
     register struct tcpcb *tp;
902636
 
902636
-    tp = (struct tcpcb *)malloc(sizeof(*tp));
902636
-    if (tp == NULL)
902636
-        return ((struct tcpcb *)0);
902636
-
902636
-    memset((char *)tp, 0, sizeof(struct tcpcb));
902636
+    tp = g_new0(struct tcpcb, 1);
902636
     tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp;
902636
     tp->t_maxseg = (so->so_ffamily == AF_INET) ? TCP_MSS : TCP6_MSS;
902636
 
902636
@@ -330,7 +326,7 @@ struct tcpcb *tcp_close(struct tcpcb *tp)
902636
         remque(tcpiphdr2qlink(tcpiphdr_prev(t)));
902636
         m_free(m);
902636
     }
902636
-    free(tp);
902636
+    g_free(tp);
902636
     so->so_tcpcb = NULL;
902636
     /* clobber input socket cache if we're closing the cached connection */
902636
     if (so == slirp->tcp_last_so)
902636
-- 
902636
1.8.3.1
902636