[Spice-devel] [PATCH 09/20] dcc: Use refcounting for MonitorsConfigItem

Jonathon Jongsma jjongsma at redhat.com
Thu Apr 14 21:50:11 UTC 2016


---
 server/dcc.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/server/dcc.c b/server/dcc.c
index b58a86a..1cd9f1a 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -510,6 +510,12 @@ void dcc_stream_agent_clip(DisplayChannelClient* dcc, StreamAgent *agent)
     red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), (PipeItem *)item);
 }
 
+static void monitors_config_item_free(MonitorsConfigItem *item)
+{
+    monitors_config_unref(item->monitors_config);
+    free(item);
+}
+
 static MonitorsConfigItem *monitors_config_item_new(RedChannel* channel,
                                                     MonitorsConfig *monitors_config)
 {
@@ -518,7 +524,8 @@ static MonitorsConfigItem *monitors_config_item_new(RedChannel* channel,
     mci = (MonitorsConfigItem *)spice_malloc(sizeof(*mci));
     mci->monitors_config = monitors_config;
 
-    pipe_item_init(&mci->pipe_item, PIPE_ITEM_TYPE_MONITORS_CONFIG);
+    pipe_item_init_full(&mci->pipe_item, PIPE_ITEM_TYPE_MONITORS_CONFIG,
+                        (GDestroyNotify)monitors_config_item_free);
     return mci;
 }
 
@@ -1591,6 +1598,7 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
     case PIPE_ITEM_TYPE_IMAGE:
     case PIPE_ITEM_TYPE_STREAM_CLIP:
     case PIPE_ITEM_TYPE_UPGRADE:
+    case PIPE_ITEM_TYPE_MONITORS_CONFIG:
         pipe_item_unref(item);
         break;
     case PIPE_ITEM_TYPE_GL_SCANOUT:
@@ -1598,13 +1606,6 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
     case PIPE_ITEM_TYPE_VERB:
         free(item);
         break;
-    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
-        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
-                                                             MonitorsConfigItem, pipe_item);
-        monitors_config_unref(monconf_item->monitors_config);
-        free(item);
-        break;
-    }
     default:
         spice_critical("invalid item type");
     }
@@ -1637,6 +1638,7 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
     case PIPE_ITEM_TYPE_STREAM_CLIP:
     case PIPE_ITEM_TYPE_UPGRADE:
     case PIPE_ITEM_TYPE_IMAGE:
+    case PIPE_ITEM_TYPE_MONITORS_CONFIG:
         pipe_item_unref(item);
         break;
     case PIPE_ITEM_TYPE_CREATE_SURFACE: {
@@ -1651,13 +1653,6 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
         free(surface_destroy);
         break;
     }
-    case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
-        MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
-                                                             MonitorsConfigItem, pipe_item);
-        monitors_config_unref(monconf_item->monitors_config);
-        free(item);
-        break;
-    }
     case PIPE_ITEM_TYPE_INVAL_ONE:
     case PIPE_ITEM_TYPE_VERB:
     case PIPE_ITEM_TYPE_MIGRATE_DATA:
-- 
2.4.11



More information about the Spice-devel mailing list