cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From bcb6107f98d7b1edf687d7afd552a4528b7e673b Mon Sep 17 00:00:00 2001
902636
From: jmaloy <jmaloy@redhat.com>
902636
Date: Tue, 12 May 2020 21:15:13 +0100
902636
Subject: [PATCH 2/7] Don't leak memory when reallocation fails.
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-2-jmaloy@redhat.com>
902636
Patchwork-id: 96412
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/2] Don't leak memory when reallocation fails.
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: Jindrich Novy <jnovy@redhat.com>
902636
902636
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
902636
[ Marc-André - modified to use a temporary variable ]
902636
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
902636
(cherry picked from libslirp commit d171af3732a0610a25334b06b77fa547bd677918)
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 | 11 +++++++----
902636
 1 file changed, 7 insertions(+), 4 deletions(-)
902636
902636
diff --git a/slirp/src/sbuf.c b/slirp/src/sbuf.c
902636
index abced48..0569c34 100644
902636
--- a/slirp/src/sbuf.c
902636
+++ b/slirp/src/sbuf.c
902636
@@ -39,13 +39,16 @@ 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
-            sb->sb_wptr = sb->sb_rptr = sb->sb_data =
902636
-                (char *)realloc(sb->sb_data, size);
902636
+            char *new = realloc(sb->sb_data, size);
902636
             sb->sb_cc = 0;
902636
-            if (sb->sb_wptr)
902636
+            if (new) {
902636
+                sb->sb_data = sb->sb_wptr = sb->sb_rptr = new;
902636
                 sb->sb_datalen = size;
902636
-            else
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
         }
902636
     } else {
902636
         sb->sb_wptr = sb->sb_rptr = sb->sb_data = (char *)malloc(size);
902636
-- 
902636
1.8.3.1
902636