From f5977dae15898efd9d9cb78c13c62b2ac4b2967e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 24 Jan 2023 20:13:50 +0000 Subject: [PATCH] rtsp-server: drop use of GSlice allocator Part-of: --- .../gst/rtsp-server/rtsp-address-pool.c | 22 +++++++++---------- .../gst/rtsp-server/rtsp-media-factory.c | 4 ++-- .../gst/rtsp-server/rtsp-media.c | 4 ++-- .../gst/rtsp-server/rtsp-mount-points.c | 4 ++-- .../gst/rtsp-server/rtsp-permissions.c | 4 ++-- .../gst/rtsp-server/rtsp-server.c | 4 ++-- .../gst/rtsp-server/rtsp-stream.c | 2 +- .../gst/rtsp-server/rtsp-thread-pool.c | 6 ++--- .../gst/rtsp-server/rtsp-token.c | 6 ++--- subprojects/gst-rtsp-server/meson.build | 5 +++++ 10 files changed, 33 insertions(+), 28 deletions(-) diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-address-pool.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-address-pool.c index da3e82b40c..eb08bf13c1 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-address-pool.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-address-pool.c @@ -60,7 +60,7 @@ gst_rtsp_address_copy (GstRTSPAddress * addr) g_return_val_if_fail (addr != NULL, NULL); - copy = g_slice_dup (GstRTSPAddress, addr); + copy = g_memdup2 (addr, sizeof (GstRTSPAddress)); /* only release to the pool when the original is freed. It's a bit * weird but this will do for now as it avoid us to use refcounting. */ copy->pool = NULL; @@ -89,7 +89,7 @@ gst_rtsp_address_free (GstRTSPAddress * addr) gst_rtsp_address_pool_release_address (addr->pool, addr); } g_free (addr->address); - g_slice_free (GstRTSPAddress, addr); + g_free (addr); } G_DEFINE_BOXED_TYPE (GstRTSPAddress, gst_rtsp_address, @@ -161,7 +161,7 @@ gst_rtsp_address_pool_init (GstRTSPAddressPool * pool) static void free_range (AddrRange * range) { - g_slice_free (AddrRange, range); + g_free (range); } static void @@ -293,7 +293,7 @@ gst_rtsp_address_pool_add_range (GstRTSPAddressPool * pool, is_multicast = ttl != 0; - range = g_slice_new0 (AddrRange); + range = g_new0 (AddrRange, 1); if (!fill_address (min_address, min_port, &range->min, is_multicast)) goto invalid; @@ -324,7 +324,7 @@ invalid: { GST_ERROR_OBJECT (pool, "invalid address range %s-%s", min_address, max_address); - g_slice_free (AddrRange, range); + g_free (range); return FALSE; } } @@ -370,7 +370,7 @@ split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr, AddrRange *temp; if (skip_addr) { - temp = g_slice_dup (AddrRange, range); + temp = g_memdup2 (range, sizeof (AddrRange)); memcpy (temp->max.bytes, temp->min.bytes, temp->min.size); inc_address (&temp->max, skip_addr - 1); priv->addresses = g_list_prepend (priv->addresses, temp); @@ -380,7 +380,7 @@ split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr, if (!RANGE_IS_SINGLE (range)) { /* min and max are not the same, we have more than one address. */ - temp = g_slice_dup (AddrRange, range); + temp = g_memdup2 (range, sizeof (AddrRange)); /* increment the range min address */ inc_address (&temp->min, 1); /* and store back in pool */ @@ -393,7 +393,7 @@ split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr, /* range now contains only one single address */ if (skip_port > 0) { /* make a range with the skipped ports */ - temp = g_slice_dup (AddrRange, range); + temp = g_memdup2 (range, sizeof (AddrRange)); temp->max.port = temp->min.port + skip_port - 1; /* and store back in pool */ priv->addresses = g_list_prepend (priv->addresses, temp); @@ -404,7 +404,7 @@ split_range (GstRTSPAddressPool * pool, AddrRange * range, guint skip_addr, /* range now contains single address with desired port number */ if (range->max.port - range->min.port + 1 > n_ports) { /* make a range with the remaining ports */ - temp = g_slice_dup (AddrRange, range); + temp = g_memdup2 (range, sizeof (AddrRange)); temp->min.port += n_ports; /* and store back in pool */ priv->addresses = g_list_prepend (priv->addresses, temp); @@ -484,7 +484,7 @@ gst_rtsp_address_pool_acquire_address (GstRTSPAddressPool * pool, g_mutex_unlock (&priv->lock); if (result) { - addr = g_slice_new0 (GstRTSPAddress); + addr = g_new0 (GstRTSPAddress, 1); addr->pool = g_object_ref (pool); addr->address = get_address_string (&result->min); addr->n_ports = n_ports; @@ -689,7 +689,7 @@ gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool, } if (addr_range) { - addr = g_slice_new0 (GstRTSPAddress); + addr = g_new0 (GstRTSPAddress, 1); addr->pool = g_object_ref (pool); addr->address = get_address_string (&addr_range->min); addr->n_ports = n_ports; diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media-factory.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media-factory.c index a044da0cfb..45d74c7a0c 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media-factory.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media-factory.c @@ -1347,7 +1347,7 @@ media_unprepared (GstRTSPMedia * media, GWeakRef * ref) static GWeakRef * weak_ref_new (gpointer obj) { - GWeakRef *ref = g_slice_new (GWeakRef); + GWeakRef *ref = g_new (GWeakRef, 1); g_weak_ref_init (ref, obj); return ref; @@ -1357,7 +1357,7 @@ static void weak_ref_free (GWeakRef * ref) { g_weak_ref_clear (ref); - g_slice_free (GWeakRef, ref); + g_free (ref); } /** diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media.c index b5c300d8a7..6f1446bc6c 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-media.c @@ -3756,7 +3756,7 @@ start_prepare (GstRTSPMedia * media) for (walk = priv->dynamic; walk; walk = g_list_next (walk)) { GstElement *elem = walk->data; - DynPaySignalHandlers *handlers = g_slice_new (DynPaySignalHandlers); + DynPaySignalHandlers *handlers = g_new (DynPaySignalHandlers, 1); GST_INFO ("adding callbacks for dynamic element %p", elem); @@ -4054,7 +4054,7 @@ finish_unprepare (GstRTSPMedia * media) g_signal_handler_disconnect (G_OBJECT (elem), handlers->no_more_pads_handler); - g_slice_free (DynPaySignalHandlers, handlers); + g_free (handlers); } gst_bin_remove (GST_BIN (priv->pipeline), priv->rtpbin); diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-mount-points.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-mount-points.c index 145c5ac7bf..ddf06c2a65 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-mount-points.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-mount-points.c @@ -54,7 +54,7 @@ data_item_new (gchar * path, gint len, GstRTSPMediaFactory * factory) { DataItem *item; - item = g_slice_alloc (sizeof (DataItem)); + item = g_new (DataItem, 1); item->path = path; item->len = len; item->factory = factory; @@ -69,7 +69,7 @@ data_item_free (gpointer data) g_free (item->path); g_object_unref (item->factory); - g_slice_free1 (sizeof (DataItem), item); + g_free (item); } static void diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-permissions.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-permissions.c index eb125489f6..8ab0373713 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-permissions.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-permissions.c @@ -73,7 +73,7 @@ _gst_rtsp_permissions_free (GstRTSPPermissions * permissions) g_ptr_array_free (impl->roles, TRUE); - g_slice_free1 (sizeof (GstRTSPPermissionsImpl), permissions); + g_free (permissions); } static GstRTSPPermissions * @@ -142,7 +142,7 @@ gst_rtsp_permissions_new (void) { GstRTSPPermissionsImpl *permissions; - permissions = g_slice_new0 (GstRTSPPermissionsImpl); + permissions = g_new0 (GstRTSPPermissionsImpl, 1); gst_rtsp_permissions_init (permissions); return GST_RTSP_PERMISSIONS (permissions); diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server.c index df5f670798..d44fc301ca 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server.c @@ -1061,7 +1061,7 @@ free_client_context (ClientContext * ctx) g_object_unref (ctx->client); g_object_unref (ctx->server); - g_slice_free (ClientContext, ctx); + g_free (ctx); return G_SOURCE_REMOVE; } @@ -1106,7 +1106,7 @@ manage_client (GstRTSPServer * server, GstRTSPClient * client) g_signal_emit (server, gst_rtsp_server_signals[SIGNAL_CLIENT_CONNECTED], 0, client); - cctx = g_slice_new0 (ClientContext); + cctx = g_new0 (ClientContext, 1); cctx->server = g_object_ref (server); cctx->client = client; diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c index 24e8e63e0b..b1348158f9 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c @@ -1612,7 +1612,7 @@ again: } if (!addr) { - addr = g_slice_new0 (GstRTSPAddress); + addr = g_new0 (GstRTSPAddress, 1); addr->port = tmp_rtp; addr->n_ports = 2; if (transport_settings_defined) diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c index 2921464f89..9e1ec69ea5 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c @@ -76,7 +76,7 @@ _gst_rtsp_thread_free (GstRTSPThreadImpl * impl) g_source_unref (impl->source); g_main_loop_unref (impl->thread.loop); g_main_context_unref (impl->thread.context); - g_slice_free1 (sizeof (GstRTSPThreadImpl), impl); + g_free (impl); } static GstRTSPThread * @@ -86,7 +86,7 @@ _gst_rtsp_thread_copy (GstRTSPThreadImpl * impl) GST_DEBUG ("copy thread %p", impl); - copy = g_slice_new0 (GstRTSPThreadImpl); + copy = g_new0 (GstRTSPThreadImpl, 1); gst_rtsp_thread_init (copy); copy->thread.context = g_main_context_ref (impl->thread.context); copy->thread.loop = g_main_loop_ref (impl->thread.loop); @@ -118,7 +118,7 @@ gst_rtsp_thread_new (GstRTSPThreadType type) { GstRTSPThreadImpl *impl; - impl = g_slice_new0 (GstRTSPThreadImpl); + impl = g_new0 (GstRTSPThreadImpl, 1); gst_rtsp_thread_init (impl); impl->thread.type = type; diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-token.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-token.c index 22f96c60e9..06f0bb895b 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-token.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-token.c @@ -68,7 +68,7 @@ _gst_rtsp_token_free (GstRTSPToken * token) gst_structure_set_parent_refcount (impl->structure, NULL); gst_structure_free (impl->structure); - g_slice_free1 (sizeof (GstRTSPTokenImpl), token); + g_free (token); } static GstRTSPToken * @@ -79,7 +79,7 @@ _gst_rtsp_token_copy (GstRTSPTokenImpl * token) structure = gst_structure_copy (token->structure); - copy = g_slice_new0 (GstRTSPTokenImpl); + copy = g_new0 (GstRTSPTokenImpl, 1); gst_rtsp_token_init (copy, structure); return (GstRTSPToken *) copy; @@ -114,7 +114,7 @@ gst_rtsp_token_new_empty (void) s = gst_structure_new_empty ("GstRTSPToken"); g_return_val_if_fail (s != NULL, NULL); - token = g_slice_new0 (GstRTSPTokenImpl); + token = g_new0 (GstRTSPTokenImpl, 1); gst_rtsp_token_init (token, s); return (GstRTSPToken *) token; diff --git a/subprojects/gst-rtsp-server/meson.build b/subprojects/gst-rtsp-server/meson.build index ec60d93870..f1c998b091 100644 --- a/subprojects/gst-rtsp-server/meson.build +++ b/subprojects/gst-rtsp-server/meson.build @@ -209,6 +209,11 @@ if gst_version_nano == 0 message('Package release date: ' + release_date) endif +glib_gio_dep = dependency('gio-2.0', version: glib_req) +if glib_gio_dep.version().version_compare('< 2.67.4') + cdata.set('g_memdup2(ptr,sz)', '(G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)') +endif + configure_file(output: 'config.h', configuration: cdata) meson.add_dist_script('scripts/gen-changelog.py', meson.project_name(), '1.20.0', meson.project_version())