[PATCH 2/2] dcc: write and use a new encoder_data_reset function to clean buffers

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

 



Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/dcc-encoders.c | 11 +++++++++++
 server/dcc-encoders.h |  2 ++
 server/dcc.c          | 37 ++++++-------------------------------
 3 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index a373412..26f3070 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -150,6 +150,17 @@ void compress_buf_free(RedCompressBuf *buf)
     g_slice_free(RedCompressBuf, buf);
 }
 
+void encoder_data_reset(EncoderData *data)
+{
+    RedCompressBuf *buf = data->bufs_head;
+    while (buf) {
+        RedCompressBuf *next = buf->send_next;
+        compress_buf_free(buf);
+        buf = next;
+    }
+    data->bufs_head = data->bufs_tail = NULL;
+}
+
 /* Allocate more space for compressed buffer.
  * The pointer returned in io_ptr is garanteed to be aligned to 4 bytes.
  */
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 4e9b66a..7046f1c 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -103,6 +103,8 @@ typedef struct  {
     char message_buf[512];
 } EncoderData;
 
+void encoder_data_reset(EncoderData *data);
+
 typedef struct {
     QuicUsrContext usr;
     EncoderData data;
diff --git a/server/dcc.c b/server/dcc.c
index 7348627..c23936a 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -702,19 +702,10 @@ int dcc_compress_image_glz(DisplayChannelClient *dcc,
 
     // the compressed buffer is bigger than the original data
     if (zlib_size >= glz_size) {
-        while (zlib_data->data.bufs_head) {
-            RedCompressBuf *buf = zlib_data->data.bufs_head;
-            zlib_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
+        encoder_data_reset(&zlib_data->data);
         goto glz;
     } else {
-        while (glz_data->data.bufs_head) {
-            RedCompressBuf *buf = glz_data->data.bufs_head;
-            glz_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
-        glz_data->data.bufs_tail = NULL;
+        encoder_data_reset(&glz_data->data);
     }
 
     dest->descriptor.type = SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB;
@@ -753,11 +744,7 @@ int dcc_compress_image_lz(DisplayChannelClient *dcc,
     lz_data->data.dcc = dcc;
 
     if (setjmp(lz_data->data.jmp_env)) {
-        while (lz_data->data.bufs_head) {
-            RedCompressBuf *buf = lz_data->data.bufs_head;
-            lz_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
+        encoder_data_reset(&lz_data->data);
         return FALSE;
     }
 
@@ -846,11 +833,7 @@ int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
     jpeg_data->data.dcc = dcc;
 
     if (setjmp(jpeg_data->data.jmp_env)) {
-        while (jpeg_data->data.bufs_head) {
-            RedCompressBuf *buf = jpeg_data->data.bufs_head;
-            jpeg_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
+        encoder_data_reset(&jpeg_data->data);
         return FALSE;
     }
 
@@ -957,11 +940,7 @@ int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
     lz4_data->data.dcc = dcc;
 
     if (setjmp(lz4_data->data.jmp_env)) {
-        while (lz4_data->data.bufs_head) {
-            RedCompressBuf *buf = lz4_data->data.bufs_head;
-            lz4_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
+        encoder_data_reset(&lz4_data->data);
         return FALSE;
     }
 
@@ -1028,11 +1007,7 @@ int dcc_compress_image_quic(DisplayChannelClient *dcc, SpiceImage *dest,
     quic_data->data.dcc = dcc;
 
     if (setjmp(quic_data->data.jmp_env)) {
-        while (quic_data->data.bufs_head) {
-            RedCompressBuf *buf = quic_data->data.bufs_head;
-            quic_data->data.bufs_head = buf->send_next;
-            compress_buf_free(buf);
-        }
+        encoder_data_reset(&quic_data->data);
         return FALSE;
     }
 
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]