cryptospore / rpms / qemu-kvm

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