[gnome-network-displays/cc-tmp: 67/80] cc: no dynamic allocation for header buffer




commit 734054dc81e71e14b2ee5b084215d24538f98095
Author: Anupam Kumar <kyteinsky gmail com>
Date:   Tue Sep 6 03:55:48 2022 +0530

    cc: no dynamic allocation for header buffer

 src/cc/cc-comm.c | 5 +----
 src/cc/cc-comm.h | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index bcdf4e9..a686ea5 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -191,11 +191,9 @@ cc_comm_header_read_cb (GObject      *source_object,
     }
 
   /* if everything is well, read all `io_bytes` */
-  message_size = GINT32_FROM_BE (*(guint32 *) comm->header_buffer);
+  message_size = GINT32_FROM_BE (comm->header_buffer);
   g_debug ("CcComm: Message size: %d", message_size);
 
-  g_clear_pointer (&comm->header_buffer, g_free);
-
   comm->message_buffer = g_malloc0 (message_size);
   g_input_stream_read_all_async (istream,
                                  comm->message_buffer,
@@ -212,7 +210,6 @@ cc_comm_read_header (CcComm *comm)
 {
   GInputStream *istream = g_io_stream_get_input_stream (G_IO_STREAM (comm->con));
 
-  comm->header_buffer = g_malloc0 (4);
   g_input_stream_read_all_async (istream,
                                  comm->header_buffer,
                                  4,
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 273cece..99dca2e 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -45,7 +45,7 @@ struct _CcComm
   CcCommClosure *closure;
 
   /*< private >*/
-  guint8 *header_buffer;
+  guint8 header_buffer [4];
   guint8 *message_buffer;
 };
 


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