mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
avoid deref
We can avoid a deref when we use container_of to get from the interface to the handle.
This commit is contained in:
parent
6b3bb79e70
commit
82414810e8
23 changed files with 433 additions and 385 deletions
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
struct _PinosSpaALSAMonitorPrivate
|
||||
|
|
@ -105,7 +106,7 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
|||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
PinosNode *node;
|
||||
void *iface;
|
||||
void *node_iface, *clock_iface;
|
||||
PinosProperties *props = NULL;
|
||||
|
||||
g_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
|
@ -119,8 +120,12 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
|||
g_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &iface)) < 0) {
|
||||
g_error ("can't get MONITOR interface: %d", res);
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &node_iface)) < 0) {
|
||||
g_error ("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.clock, &clock_iface)) < 0) {
|
||||
g_error ("can't get CLOCK interface: %d", res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +143,8 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
|||
node = g_object_new (PINOS_TYPE_NODE,
|
||||
"daemon", priv->daemon,
|
||||
"name", item->factory->name,
|
||||
"node", iface,
|
||||
"node", node_iface,
|
||||
"clock", clock_iface,
|
||||
"properties", props,
|
||||
NULL);
|
||||
|
||||
|
|
@ -203,6 +209,7 @@ monitor_constructed (GObject * object)
|
|||
G_OBJECT_CLASS (pinos_spa_alsa_monitor_parent_class)->constructed (object);
|
||||
|
||||
priv->uri.node = spa_id_map_get_id (priv->daemon->map, SPA_NODE_URI);
|
||||
priv->uri.clock = spa_id_map_get_id (priv->daemon->map, SPA_CLOCK_URI);
|
||||
|
||||
while (TRUE) {
|
||||
SpaMonitorItem *item;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
struct _PinosSpaAudioTestSrcPrivate
|
||||
{
|
||||
PinosRingbuffer *ringbuffer;
|
||||
|
||||
SpaHandle *handle;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -40,9 +42,8 @@ enum {
|
|||
G_DEFINE_TYPE (PinosSpaAudioTestSrc, pinos_spa_audiotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *name)
|
||||
make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
|
@ -68,16 +69,16 @@ make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *nam
|
|||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
*handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory,
|
||||
handle,
|
||||
*handle,
|
||||
NULL,
|
||||
daemon->support,
|
||||
daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
if ((res = spa_handle_get_interface (*handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
|
|
@ -145,12 +146,12 @@ src_constructed (GObject * object)
|
|||
static void
|
||||
src_finalize (GObject * object)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (object);
|
||||
PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object);
|
||||
PinosSpaAudioTestSrcPrivate *priv = src->priv;
|
||||
|
||||
g_debug ("audiotestsrc %p: dispose", src);
|
||||
spa_handle_clear (node->node->handle);
|
||||
g_free (node->node->handle);
|
||||
spa_handle_clear (priv->handle);
|
||||
g_free (priv->handle);
|
||||
|
||||
G_OBJECT_CLASS (pinos_spa_audiotestsrc_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -182,8 +183,10 @@ pinos_spa_audiotestsrc_new (PinosDaemon *daemon,
|
|||
PinosNode *node;
|
||||
SpaNode *n;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
|
||||
if ((res = make_node (daemon,
|
||||
&handle,
|
||||
&n,
|
||||
"build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so",
|
||||
"audiotestsrc")) < 0) {
|
||||
|
|
@ -198,5 +201,7 @@ pinos_spa_audiotestsrc_new (PinosDaemon *daemon,
|
|||
"node", n,
|
||||
NULL);
|
||||
|
||||
PINOS_SPA_AUDIOTESTSRC (node)->priv->handle = handle;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
struct _PinosSpaV4l2MonitorPrivate
|
||||
|
|
@ -105,7 +106,8 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
PinosNode *node;
|
||||
void *iface;
|
||||
void *node_iface;
|
||||
void *clock_iface;
|
||||
PinosProperties *props = NULL;
|
||||
|
||||
g_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
|
@ -119,10 +121,14 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
g_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &node_iface)) < 0) {
|
||||
g_error ("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.clock, &clock_iface)) < 0) {
|
||||
g_error ("can't get CLOCK interface: %d", res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item->info) {
|
||||
unsigned int i;
|
||||
|
|
@ -138,7 +144,8 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
node = g_object_new (PINOS_TYPE_NODE,
|
||||
"daemon", priv->daemon,
|
||||
"name", item->factory->name,
|
||||
"node", iface,
|
||||
"node", node_iface,
|
||||
"clock", clock_iface,
|
||||
"properties", props,
|
||||
NULL);
|
||||
|
||||
|
|
@ -203,6 +210,7 @@ monitor_constructed (GObject * object)
|
|||
G_OBJECT_CLASS (pinos_spa_v4l2_monitor_parent_class)->constructed (object);
|
||||
|
||||
priv->uri.node = spa_id_map_get_id (priv->daemon->map, SPA_NODE_URI);
|
||||
priv->uri.clock = spa_id_map_get_id (priv->daemon->map, SPA_CLOCK_URI);
|
||||
|
||||
while (TRUE) {
|
||||
SpaMonitorItem *item;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
struct _PinosSpaVideoTestSrcPrivate
|
||||
{
|
||||
gint dummy;
|
||||
SpaHandle *handle;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -39,9 +39,8 @@ enum {
|
|||
G_DEFINE_TYPE (PinosSpaVideoTestSrc, pinos_spa_videotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *name)
|
||||
make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
|
@ -67,14 +66,14 @@ make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *nam
|
|||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = factory->init (factory, handle, NULL, daemon->support, daemon->n_support)) < 0) {
|
||||
*handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, *handle, NULL, daemon->support, daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = handle->get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (*handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -113,12 +112,12 @@ set_property (GObject *object,
|
|||
static void
|
||||
source_finalize (GObject * object)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (object);
|
||||
PinosSpaVideoTestSrc *source = PINOS_SPA_VIDEOTESTSRC (object);
|
||||
PinosSpaVideoTestSrcPrivate *priv = source->priv;
|
||||
|
||||
g_debug ("spa-source %p: dispose", source);
|
||||
spa_handle_clear (node->node->handle);
|
||||
g_free (node->node->handle);
|
||||
spa_handle_clear (priv->handle);
|
||||
g_free (priv->handle);
|
||||
|
||||
G_OBJECT_CLASS (pinos_spa_videotestsrc_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -149,8 +148,10 @@ pinos_spa_videotestsrc_new (PinosDaemon *daemon,
|
|||
PinosNode *node;
|
||||
SpaNode *n;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
|
||||
if ((res = make_node (daemon,
|
||||
&handle,
|
||||
&n,
|
||||
"build/spa/plugins/videotestsrc/libspa-videotestsrc.so",
|
||||
"videotestsrc")) < 0) {
|
||||
|
|
@ -165,5 +166,7 @@ pinos_spa_videotestsrc_new (PinosDaemon *daemon,
|
|||
"node", n,
|
||||
NULL);
|
||||
|
||||
PINOS_SPA_VIDEOTESTSRC (node)->priv->handle = handle;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue