[spice-gtk] channel-usbredir: Remove leak of decompressed buffer

Submitted by Frediano Ziglio on July 11, 2019, 12:58 p.m.

Details

Message ID 20190711125857.17701-1-fziglio@redhat.com
State Accepted
Commit 8414e1b023a25394f874444bac7ed4a734404e70
Headers show
Series "channel-usbredir: Remove leak of decompressed buffer" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 11, 2019, 12:58 p.m.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 src/channel-usbredir.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 76534180..04acf0bd 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -724,6 +724,7 @@  static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
         if (try_handle_compressed_msg(compressed_data_msg, &buf, &size)) {
             /* uncompressed ok*/
         } else {
+            buf = NULL;
             r = USB_REDIR_ERROR_READ_PARSE;
         }
     } else { /* Regular SPICE_MSG_SPICEVMC_DATA msg */
@@ -733,17 +734,12 @@  static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
     spice_usbredir_channel_lock(channel);
     if (r == 0)
         r = spice_usb_backend_read_guest_data(priv->host, buf, size);
-    if (r != 0) {
+    if (r != 0 && priv->spice_device != NULL) {
         SpiceUsbDevice *spice_device = priv->spice_device;
         device_error_data err_data;
         gchar *desc;
         GError *err;
 
-        if (spice_device == NULL) {
-            spice_usbredir_channel_unlock(channel);
-            return;
-        }
-
         desc = spice_usb_device_get_description(spice_device, NULL);
         err = spice_usb_backend_get_error_details(r, desc);
         g_free(desc);
@@ -764,6 +760,9 @@  static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
     } else {
         spice_usbredir_channel_unlock(channel);
     }
+    if (spice_msg_in_type(in) == SPICE_MSG_SPICEVMC_COMPRESSED_DATA) {
+        g_free(buf);
+    }
 }
 
 #else

Comments