[libsoup/websockets-extension-buffer-error: 2/2] WebSockets: plug a couple of leaks in case of error with the deflate extension



commit 1a029e30ba0aa99f9e4813fafd86875d77a36cb1
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Fri Aug 30 15:17:17 2019 +0300

    WebSockets: plug a couple of leaks in case of error with the deflate extension
    
    Also remove a spurious unref in the caller while handling the error,
    which shouldn't be needed as the extension returns NULL in case of
    error.

 libsoup/soup-websocket-connection.c        | 2 --
 libsoup/soup-websocket-extension-deflate.c | 9 +++++----
 2 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/libsoup/soup-websocket-connection.c b/libsoup/soup-websocket-connection.c
index cec4de37..b5f1455f 100644
--- a/libsoup/soup-websocket-connection.c
+++ b/libsoup/soup-websocket-connection.c
@@ -1077,8 +1077,6 @@ process_frame (SoupWebsocketConnection *self)
                filtered_bytes = soup_websocket_extension_process_incoming_message (extension, 
self->pv->incoming->data, filtered_bytes, &error);
                if (error) {
                        emit_error_and_close (self, error, FALSE);
-                       g_bytes_unref (filtered_bytes);
-
                        return FALSE;
                }
        }
diff --git a/libsoup/soup-websocket-extension-deflate.c b/libsoup/soup-websocket-extension-deflate.c
index 01faf3fc..dda27c73 100644
--- a/libsoup/soup-websocket-extension-deflate.c
+++ b/libsoup/soup-websocket-extension-deflate.c
@@ -355,6 +355,8 @@ soup_websocket_extension_deflate_process_outgoing_message (SoupWebsocketExtensio
                 bytes_written += write_remaining - priv->deflater.zstream.avail_out;
         } while (result == Z_OK);
 
+        g_bytes_unref (payload);
+
         if (result != Z_BUF_ERROR || bytes_written < 4) {
                 g_set_error_literal (error,
                                      SOUP_WEBSOCKET_ERROR,
@@ -368,8 +370,6 @@ soup_websocket_extension_deflate_process_outgoing_message (SoupWebsocketExtensio
         /* Remove 4 octets (that are 0x00 0x00 0xff 0xff) from the tail end. */
         g_byte_array_set_size (buffer, bytes_written - 4);
 
-        g_bytes_unref (payload);
-
         deflater_reset (&priv->deflater);
 
         return g_byte_array_free_to_bytes (buffer);
@@ -410,6 +410,7 @@ soup_websocket_extension_deflate_process_incoming_message (SoupWebsocketExtensio
                                      SOUP_WEBSOCKET_ERROR,
                                      SOUP_WEBSOCKET_CLOSE_PROTOCOL_ERROR,
                                      "Received a non-first frame with RSV1 flag set");
+                g_bytes_unref (payload);
                 return NULL;
         }
 
@@ -467,6 +468,8 @@ soup_websocket_extension_deflate_process_incoming_message (SoupWebsocketExtensio
                         break;
         } while (result == Z_OK || result == Z_BUF_ERROR);
 
+        g_bytes_unref (payload);
+
         if (result != Z_OK && result != Z_BUF_ERROR) {
                 priv->inflater.uncompress_ongoing = FALSE;
                 g_set_error_literal (error,
@@ -480,8 +483,6 @@ soup_websocket_extension_deflate_process_incoming_message (SoupWebsocketExtensio
 
         g_byte_array_set_size (buffer, bytes_written);
 
-        g_bytes_unref (payload);
-
         return g_byte_array_free_to_bytes (buffer);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]