thebeanogamer / rpms / qemu-kvm

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