[Spice-devel] [PATCH spice-server v2 23/23] red-pipe-item: Use GLib memory functions

Jonathon Jongsma jjongsma at redhat.com
Fri Sep 22 22:20:54 UTC 2017


Acked-by: Jonathon Jongsma <jjongsma at redhat.com>


On Wed, 2017-09-20 at 08:51 +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/cache-item.tmpl.c          |  6 +++---
>  server/dcc.c                      | 10 +++++-----
>  server/inputs-channel.c           |  4 ++--
>  server/main-channel-client.c      | 14 +++++++-------
>  server/red-channel-client.c       |  8 ++++----
>  server/red-channel.c              |  2 +-
>  server/red-pipe-item.c            |  2 +-
>  server/smartcard-channel-client.c |  2 +-
>  server/spicevmc.c                 |  6 +++---
>  server/stream.c                   |  2 +-
>  10 files changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/server/cache-item.tmpl.c b/server/cache-item.tmpl.c
> index 19e6b95f1..44b45f812 100644
> --- a/server/cache-item.tmpl.c
> +++ b/server/cache-item.tmpl.c
> @@ -86,7 +86,7 @@ static int FUNC_NAME(add)(CHANNELCLIENT
> *channel_client, uint64_t id, size_t siz
>      RedCacheItem *item;
>      int key;
>  
> -    item = spice_new(RedCacheItem, 1);
> +    item = g_new(RedCacheItem, 1);
>  
>      channel_client->priv->VAR_NAME(available) -= size;
>      SPICE_VERIFY(SPICE_OFFSETOF(RedCacheItem, u.cache_data.lru_link)
> == 0);
> @@ -94,7 +94,7 @@ static int FUNC_NAME(add)(CHANNELCLIENT
> *channel_client, uint64_t id, size_t siz
>          RedCacheItem *tail = (RedCacheItem
> *)ring_get_tail(&channel_client->priv->VAR_NAME(lru));
>          if (!tail) {
>              channel_client->priv->VAR_NAME(available) += size;
> -            free(item);
> +            g_free(item);
>              return FALSE;
>          }
>          FUNC_NAME(remove)(channel_client, tail);
> @@ -117,7 +117,7 @@ static void FUNC_NAME(reset)(CHANNELCLIENT
> *channel_client, long size)
>          while (channel_client->priv->CACHE_NAME[i]) {
>              RedCacheItem *item = channel_client->priv-
> >CACHE_NAME[i];
>              channel_client->priv->CACHE_NAME[i] = item-
> >u.cache_data.next;
> -            free(item);
> +            g_free(item);
>          }
>      }
>      ring_init(&channel_client->priv->VAR_NAME(lru));
> diff --git a/server/dcc.c b/server/dcc.c
> index 2c1761d28..d7927c08f 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -194,7 +194,7 @@ static RedSurfaceCreateItem
> *red_surface_create_item_new(RedChannel* channel,
>  {
>      RedSurfaceCreateItem *create;
>  
> -    create = spice_new(RedSurfaceCreateItem, 1);
> +    create = g_new(RedSurfaceCreateItem, 1);
>  
>      create->surface_create.surface_id = surface_id;
>      create->surface_create.width = width;
> @@ -340,7 +340,7 @@ RedImageItem
> *dcc_add_surface_area_image(DisplayChannelClient *dcc,
>      bpp = SPICE_SURFACE_FMT_DEPTH(surface->context.format) / 8;
>      stride = width * bpp;
>  
> -    item = (RedImageItem *)spice_malloc_n_m(height, stride,
> sizeof(RedImageItem));
> +    item = (RedImageItem *)g_malloc(height * stride +
> sizeof(RedImageItem));
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_IMAGE);
>  
> @@ -689,7 +689,7 @@ static RedSurfaceDestroyItem
> *red_surface_destroy_item_new(RedChannel *channel,
>  {
>      RedSurfaceDestroyItem *destroy;
>  
> -    destroy = spice_new(RedSurfaceDestroyItem, 1);
> +    destroy = g_new(RedSurfaceDestroyItem, 1);
>      destroy->surface_destroy.surface_id = surface_id;
>      red_pipe_item_init(&destroy->pipe_item,
> RED_PIPE_ITEM_TYPE_DESTROY_SURFACE);
>  
> @@ -708,7 +708,7 @@ RedPipeItem
> *dcc_gl_scanout_item_new(RedChannelClient *rcc, void *data, int num)
>          return NULL;
>      }
>  
> -    item = spice_new(RedGlScanoutUnixItem, 1);
> +    item = g_new(RedGlScanoutUnixItem, 1);
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_GL_SCANOUT);
>  
>      return &item->base;
> @@ -728,7 +728,7 @@ RedPipeItem
> *dcc_gl_draw_item_new(RedChannelClient *rcc, void *data, int num)
>      }
>  
>      dcc->priv->gl_draw_ongoing = TRUE;
> -    item = spice_new(RedGlDrawItem, 1);
> +    item = g_new(RedGlDrawItem, 1);
>      item->draw = *draw;
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_GL_DRAW);
>  
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index b8944cb0f..96fd87399 100644
> --- a/server/inputs-channel.c
> +++ b/server/inputs-channel.c
> @@ -196,7 +196,7 @@ static uint8_t kbd_get_leds(SpiceKbdInstance
> *sin)
>  
>  static RedPipeItem *red_inputs_key_modifiers_item_new(uint8_t
> modifiers)
>  {
> -    RedKeyModifiersPipeItem *item =
> spice_malloc(sizeof(RedKeyModifiersPipeItem));
> +    RedKeyModifiersPipeItem *item = g_new(RedKeyModifiersPipeItem,
> 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_KEY_MODIFIERS);
>      item->modifiers = modifiers;
> @@ -435,7 +435,7 @@ void inputs_release_keys(InputsChannel *inputs)
>  
>  static void inputs_pipe_add_init(RedChannelClient *rcc)
>  {
> -    RedInputsInitPipeItem *item =
> spice_malloc(sizeof(RedInputsInitPipeItem));
> +    RedInputsInitPipeItem *item = g_new(RedInputsInitPipeItem, 1);
>      InputsChannel *inputs =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_INPUTS_INIT);
> diff --git a/server/main-channel-client.c b/server/main-channel-
> client.c
> index b7b60eddb..bdcc1e825 100644
> --- a/server/main-channel-client.c
> +++ b/server/main-channel-client.c
> @@ -274,7 +274,7 @@ void
> main_channel_client_start_net_test(MainChannelClient *mcc, int
> test_rate)
>  
>  static RedPipeItem *red_ping_item_new(int size)
>  {
> -    RedPingPipeItem *item = spice_malloc(sizeof(RedPingPipeItem));
> +    RedPingPipeItem *item = g_new(RedPingPipeItem, 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_PING);
>      item->size = size;
> @@ -295,7 +295,7 @@ static bool
> main_channel_client_push_ping(MainChannelClient *mcc, int size)
>  
>  static RedPipeItem *main_agent_tokens_item_new(uint32_t num_tokens)
>  {
> -    RedTokensPipeItem *item =
> spice_malloc(sizeof(RedTokensPipeItem));
> +    RedTokensPipeItem *item = g_new(RedTokensPipeItem, 1);
>  
>      red_pipe_item_init(&item->base,
> RED_PIPE_ITEM_TYPE_MAIN_AGENT_TOKEN);
>      item->tokens = num_tokens;
> @@ -348,7 +348,7 @@ static RedPipeItem *main_init_item_new(int
> connection_id,
>                                         int multi_media_time,
>                                         int ram_hint)
>  {
> -    RedInitPipeItem *item = spice_malloc(sizeof(RedInitPipeItem));
> +    RedInitPipeItem *item = g_new(RedInitPipeItem, 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_INIT);
>      item->connection_id = connection_id;
> @@ -377,7 +377,7 @@ void
> main_channel_client_push_init(MainChannelClient *mcc,
>  
>  static RedPipeItem *main_name_item_new(const char *name)
>  {
> -    RedNamePipeItem *item = spice_malloc(sizeof(RedNamePipeItem) +
> strlen(name) + 1);
> +    RedNamePipeItem *item = g_malloc(sizeof(RedNamePipeItem) +
> strlen(name) + 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_NAME);
>      item->msg.name_len = strlen(name) + 1;
> @@ -400,7 +400,7 @@ void
> main_channel_client_push_name(MainChannelClient *mcc, const char
> *name)
>  
>  static RedPipeItem *main_uuid_item_new(const uint8_t uuid[16])
>  {
> -    RedUuidPipeItem *item = spice_malloc(sizeof(RedUuidPipeItem));
> +    RedUuidPipeItem *item = g_new(RedUuidPipeItem, 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_UUID);
>      memcpy(item->msg.uuid, uuid, sizeof(item->msg.uuid));
> @@ -428,7 +428,7 @@ void
> main_channel_client_push_notify(MainChannelClient *mcc, const char
> *msg)
>  
>  RedPipeItem *main_mouse_mode_item_new(SpiceMouseMode current_mode,
> int is_client_mouse_allowed)
>  {
> -    RedMouseModePipeItem *item =
> spice_malloc(sizeof(RedMouseModePipeItem));
> +    RedMouseModePipeItem *item = g_new(RedMouseModePipeItem, 1);
>  
>      red_pipe_item_init(&item->base,
> RED_PIPE_ITEM_TYPE_MAIN_MOUSE_MODE);
>      item->current_mode = current_mode;
> @@ -440,7 +440,7 @@ RedPipeItem
> *main_multi_media_time_item_new(uint32_t mm_time)
>  {
>      RedMultiMediaTimePipeItem *item;
>  
> -    item = spice_malloc(sizeof(RedMultiMediaTimePipeItem));
> +    item = g_new(RedMultiMediaTimePipeItem, 1);
>      red_pipe_item_init(&item->base,
> RED_PIPE_ITEM_TYPE_MAIN_MULTI_MEDIA_TIME);
>      item->time = mm_time;
>      return &item->base;
> diff --git a/server/red-channel-client.c b/server/red-channel-
> client.c
> index a8c6f33fd..ea6827cff 100644
> --- a/server/red-channel-client.c
> +++ b/server/red-channel-client.c
> @@ -1608,7 +1608,7 @@ void
> red_channel_client_pipe_add_tail(RedChannelClient *rcc,
>  
>  void red_channel_client_pipe_add_type(RedChannelClient *rcc, int
> pipe_item_type)
>  {
> -    RedPipeItem *item = spice_new(RedPipeItem, 1);
> +    RedPipeItem *item = g_new(RedPipeItem, 1);
>  
>      red_pipe_item_init(item, pipe_item_type);
>      red_channel_client_pipe_add(rcc, item);
> @@ -1616,7 +1616,7 @@ void
> red_channel_client_pipe_add_type(RedChannelClient *rcc, int
> pipe_item_type)
>  
>  RedPipeItem *red_channel_client_new_empty_msg(int msg_type)
>  {
> -    RedEmptyMsgPipeItem *item = spice_new(RedEmptyMsgPipeItem, 1);
> +    RedEmptyMsgPipeItem *item = g_new(RedEmptyMsgPipeItem, 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_EMPTY_MSG);
>      item->msg = msg_type;
> @@ -1765,7 +1765,7 @@ static void marker_pipe_item_free(RedPipeItem
> *base)
>      if (item->item_in_pipe) {
>          *item->item_in_pipe = FALSE;
>      }
> -    free(item);
> +    g_free(item);
>  }
>  
>  /* TODO: more evil sync stuff. anything with the word wait in it's
> name. */
> @@ -1784,7 +1784,7 @@ bool
> red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>          end_time = UINT64_MAX;
>      }
>  
> -    MarkerPipeItem *mark_item = spice_new0(MarkerPipeItem, 1);
> +    MarkerPipeItem *mark_item = g_new0(MarkerPipeItem, 1);
>  
>      red_pipe_item_init_full(&mark_item->base,
> RED_PIPE_ITEM_TYPE_MARKER,
>                              marker_pipe_item_free);
> diff --git a/server/red-channel.c b/server/red-channel.c
> index b5094829e..9736c54b1 100644
> --- a/server/red-channel.c
> +++ b/server/red-channel.c
> @@ -443,7 +443,7 @@ void red_channel_pipes_add(RedChannel *channel,
> RedPipeItem *item)
>  
>  void red_channel_pipes_add_type(RedChannel *channel, int
> pipe_item_type)
>  {
> -    RedPipeItem *item = spice_new(RedPipeItem, 1);
> +    RedPipeItem *item = g_new(RedPipeItem, 1);
>  
>      red_pipe_item_init(item, pipe_item_type);
>  
> diff --git a/server/red-pipe-item.c b/server/red-pipe-item.c
> index 2cb584731..821b5f961 100644
> --- a/server/red-pipe-item.c
> +++ b/server/red-pipe-item.c
> @@ -44,7 +44,7 @@ void red_pipe_item_init_full(RedPipeItem *item,
>  {
>      item->type = type;
>      item->refcount = 1;
> -    item->free_func = free_func ? free_func : (red_pipe_item_free_t
> *)free;
> +    item->free_func = free_func ? free_func : (red_pipe_item_free_t
> *)g_free;
>  }
>  
>  void marshaller_unref_pipe_item(uint8_t *data G_GNUC_UNUSED, void
> *opaque)
> diff --git a/server/smartcard-channel-client.c b/server/smartcard-
> channel-client.c
> index 07d451f47..b1652e769 100644
> --- a/server/smartcard-channel-client.c
> +++ b/server/smartcard-channel-client.c
> @@ -215,7 +215,7 @@ static void
> smartcard_channel_client_push_error(RedChannelClient *rcc,
>                                                  uint32_t reader_id,
>                                                  VSCErrorCode error)
>  {
> -    RedErrorItem *error_item = spice_new0(RedErrorItem, 1);
> +    RedErrorItem *error_item = g_new0(RedErrorItem, 1);
>  
>      red_pipe_item_init(&error_item->base, RED_PIPE_ITEM_TYPE_ERROR);
>  
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index 7577165f5..45036c470 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -351,7 +351,7 @@ static RedVmcPipeItem*
> try_compress_lz4(RedVmcChannel *channel, int n, RedVmcPip
>          /* Client doesn't have compression cap - data will not be
> compressed */
>          return NULL;
>      }
> -    msg_item_compressed = spice_new0(RedVmcPipeItem, 1);
> +    msg_item_compressed = g_new0(RedVmcPipeItem, 1);
>      red_pipe_item_init(&msg_item_compressed->base,
> RED_PIPE_ITEM_TYPE_SPICEVMC_DATA);
>      compressed_data_count = LZ4_compress_default((char*)&msg_item-
> >buf,
>                                                   (char*)&msg_item_co
> mpressed->buf,
> @@ -390,7 +390,7 @@ static RedPipeItem
> *spicevmc_chardev_read_msg_from_dev(RedCharDevice *self,
>      }
>  
>      if (!channel->pipe_item) {
> -        msg_item = spice_new0(RedVmcPipeItem, 1);
> +        msg_item = g_new0(RedVmcPipeItem, 1);
>          msg_item->type = SPICE_DATA_COMPRESSION_TYPE_NONE;
>          red_pipe_item_init(&msg_item->base,
> RED_PIPE_ITEM_TYPE_SPICEVMC_DATA);
>      } else {
> @@ -455,7 +455,7 @@ static void
> spicevmc_port_send_init(RedChannelClient *rcc)
>  
>  static void spicevmc_port_send_event(RedChannelClient *rcc, uint8_t
> event)
>  {
> -    RedPortEventPipeItem *item = spice_new(RedPortEventPipeItem, 1);
> +    RedPortEventPipeItem *item = g_new(RedPortEventPipeItem, 1);
>  
>      red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_PORT_EVENT);
>      item->event = event;
> diff --git a/server/stream.c b/server/stream.c
> index e674161a1..24f5b4195 100644
> --- a/server/stream.c
> +++ b/server/stream.c
> @@ -741,7 +741,7 @@ void dcc_create_stream(DisplayChannelClient *dcc,
> Stream *stream)
>      red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc),
> stream_create_item_new(agent));
>  
>      if (red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(dcc),
> SPICE_DISPLAY_CAP_STREAM_REPORT)) {
> -        RedStreamActivateReportItem *report_pipe_item =
> spice_malloc0(sizeof(*report_pipe_item));
> +        RedStreamActivateReportItem *report_pipe_item =
> g_new0(RedStreamActivateReportItem, 1);
>  
>          agent->report_id = rand();
>          red_pipe_item_init(&report_pipe_item->pipe_item,


More information about the Spice-devel mailing list