diff --git a/spa/include/spa/support/plugin.h b/spa/include/spa/support/plugin.h index 4b49306dd..c7e83a82a 100644 --- a/spa/include/spa/support/plugin.h +++ b/spa/include/spa/support/plugin.h @@ -107,9 +107,14 @@ struct spa_handle_factory { */ const struct spa_dict *info; /** - * The size of handles from this factory + * Get the size of handles from this factory. + * + * \param factory a spa_handle_factory + * \param params extra parameters that determine the size of the + * handle. */ - const size_t size; + size_t (*get_size) (const struct spa_handle_factory *factory, + const struct spa_dict *params); /** * Initialize an instance of this factory. The caller should allocate @@ -150,6 +155,7 @@ struct spa_handle_factory { uint32_t *index); }; +#define spa_handle_factory_get_size(h,...) (h)->get_size((h),__VA_ARGS__) #define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__) #define spa_handle_factory_enum_interface_info(h,...) (h)->enum_interface_info((h),__VA_ARGS__) diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index 08a4adfae..0c5d43714 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -479,6 +479,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -545,7 +552,7 @@ const struct spa_handle_factory spa_alsa_monitor_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 0e4167dfb..b75a670f2 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -658,6 +658,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct state); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, const struct spa_dict *info, const struct spa_support *support, uint32_t n_support) @@ -754,7 +761,7 @@ const struct spa_handle_factory spa_alsa_sink_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, &info, - sizeof(struct state), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index 808dd6100..150baebff 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -713,6 +713,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct state); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -812,7 +819,7 @@ const struct spa_handle_factory spa_alsa_source_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, &info, - sizeof(struct state), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index bdd8f75c8..a3ff89688 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -898,6 +898,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -974,7 +981,7 @@ const struct spa_handle_factory spa_audioconvert_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index b08eb7fe0..c6f79db01 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -871,6 +871,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -947,7 +954,7 @@ const struct spa_handle_factory spa_channelmix_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index 51110b28d..fb8d49c39 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -927,6 +927,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1003,7 +1010,7 @@ const struct spa_handle_factory spa_fmtconvert_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index f8bc5c2fd..af80e6cbc 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -1114,6 +1114,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1187,7 +1194,7 @@ const struct spa_handle_factory spa_audiomixer_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 50e43f64f..ee3f90143 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -1146,6 +1146,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1250,7 +1257,7 @@ const struct spa_handle_factory spa_audiotestsrc_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, &info, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 65df300bd..df74e2056 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -1340,6 +1340,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1439,7 +1446,7 @@ struct spa_handle_factory spa_a2dp_sink_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, &info, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/bluez5/bluez5-monitor.c b/spa/plugins/bluez5/bluez5-monitor.c index 2e65f1a1b..b0f15c434 100644 --- a/spa/plugins/bluez5/bluez5-monitor.c +++ b/spa/plugins/bluez5/bluez5-monitor.c @@ -1180,6 +1180,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct spa_bt_monitor); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1257,7 +1264,7 @@ static const struct spa_handle_factory spa_bluez5_monitor_factory = { SPA_VERSION_MONITOR, NAME, NULL, - sizeof(struct spa_bt_monitor), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/support/dbus.c b/spa/plugins/support/dbus.c index 8f9787352..3e1db92a0 100644 --- a/spa/plugins/support/dbus.c +++ b/spa/plugins/support/dbus.c @@ -353,6 +353,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -426,7 +433,7 @@ static const struct spa_handle_factory dbus_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index ce5deafd0..b514ec3aa 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -180,6 +180,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -259,7 +266,7 @@ static const struct spa_handle_factory logger_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c index c73cdfbca..0dd7cc97d 100644 --- a/spa/plugins/support/loop.c +++ b/spa/plugins/support/loop.c @@ -690,6 +690,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -766,7 +773,7 @@ static const struct spa_handle_factory loop_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info }; diff --git a/spa/plugins/support/mapper.c b/spa/plugins/support/mapper.c index b1f5ba0ed..f2a40335b 100644 --- a/spa/plugins/support/mapper.c +++ b/spa/plugins/support/mapper.c @@ -154,6 +154,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -206,7 +213,7 @@ static const struct spa_handle_factory type_map_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c index fecfd7003..0d63361cf 100644 --- a/spa/plugins/test/fakesink.c +++ b/spa/plugins/test/fakesink.c @@ -840,6 +840,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -929,7 +936,7 @@ const struct spa_handle_factory spa_fakesink_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index 8540fa1d6..a286794d3 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -875,6 +875,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -964,7 +971,7 @@ const struct spa_handle_factory spa_fakesrc_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index 50789ff3a..12a6c1270 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -337,6 +337,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -403,7 +410,7 @@ const struct spa_handle_factory spa_v4l2_monitor_factory = { SPA_VERSION_MONITOR, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 720a43322..27394f01c 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -975,6 +975,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1065,7 +1072,7 @@ const struct spa_handle_factory spa_v4l2_source_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index db9066076..814cb9217 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -986,6 +986,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -1085,7 +1092,7 @@ const struct spa_handle_factory spa_videotestsrc_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, &info, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index f772e5d34..ac100080d 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -899,6 +899,13 @@ static int impl_clear(struct spa_handle *handle) return 0; } +static size_t +impl_get_size(const struct spa_handle_factory *factory, + const struct spa_dict *params) +{ + return sizeof(struct impl); +} + static int impl_init(const struct spa_handle_factory *factory, struct spa_handle *handle, @@ -971,7 +978,7 @@ const struct spa_handle_factory spa_volume_factory = { SPA_VERSION_HANDLE_FACTORY, NAME, NULL, - sizeof(struct impl), + impl_get_size, impl_init, impl_enum_interface_info, }; diff --git a/spa/tests/test-bluez5.c b/spa/tests/test-bluez5.c index abea5fe9d..29a54da52 100644 --- a/spa/tests/test-bluez5.c +++ b/spa/tests/test-bluez5.c @@ -188,7 +188,7 @@ static int get_handle(struct data *data, if (strcmp(factory->name, name)) continue; - *handle = calloc(1, factory->size); + *handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, *handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-control.c b/spa/tests/test-control.c index 6450d92a5..3ee26c4bd 100644 --- a/spa/tests/test-control.c +++ b/spa/tests/test-control.c @@ -216,7 +216,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-convert.c b/spa/tests/test-convert.c index bb2505739..c963b09f4 100644 --- a/spa/tests/test-convert.c +++ b/spa/tests/test-convert.c @@ -183,7 +183,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-convert2.c b/spa/tests/test-convert2.c index 87e62f1e8..54a53cba7 100644 --- a/spa/tests/test-convert2.c +++ b/spa/tests/test-convert2.c @@ -144,7 +144,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index f65e3cb71..6b003b9ec 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -213,7 +213,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 01784eb2a..d52d4eb29 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -233,7 +233,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-perf.c b/spa/tests/test-perf.c index adc59f17a..890c78983 100644 --- a/spa/tests/test-perf.c +++ b/spa/tests/test-perf.c @@ -209,7 +209,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index 5816aa805..e39703c1f 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -187,7 +187,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index 0e67f1bf1..57f37114b 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -155,7 +155,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, if (strcmp(factory->name, name)) continue; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index e25fbf12d..668b07a9b 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -210,7 +210,7 @@ static void inspect_factory(struct data *data, const struct spa_handle_factory * printf(" interface: '%s'\n", info->type); } - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data->support, data->n_support)) < 0) { printf("can't make factory instance: %d\n", res); diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index d4afeafda..9e252acaf 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -224,7 +224,7 @@ int main(int argc, char *argv[]) struct spa_handle *handle; void *interface; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, data.support, data.n_support)) < 0) { diff --git a/src/modules/module-mixer.c b/src/modules/module-mixer.c index 06f2991b9..4fb14208d 100644 --- a/src/modules/module-mixer.c +++ b/src/modules/module-mixer.c @@ -109,7 +109,10 @@ static struct pw_node *make_node(struct impl *impl, struct pw_properties *proper support = pw_core_get_support(impl->core, &n_support); - handle = calloc(1, impl->factory->size); + handle = calloc(1, spa_handle_factory_get_size(impl->factory, NULL)); + if (handle == NULL) + goto no_mem; + if ((res = spa_handle_factory_init(impl->factory, handle, NULL, support, n_support)) < 0) { @@ -140,6 +143,7 @@ static struct pw_node *make_node(struct impl *impl, struct pw_properties *proper spa_handle_clear(handle); init_failed: free(handle); + no_mem: return NULL; } diff --git a/src/modules/spa/spa-monitor.c b/src/modules/spa/spa-monitor.c index ea84555f8..f3ec7c2d6 100644 --- a/src/modules/spa/spa-monitor.c +++ b/src/modules/spa/spa-monitor.c @@ -103,7 +103,7 @@ static void add_item(struct pw_spa_monitor *this, struct spa_pod *item) support = pw_core_get_support(impl->core, &n_support); - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, &props->dict, @@ -292,8 +292,12 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core, if (strcmp(factory->name, factory_name) == 0) break; } + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); + if (handle == NULL) + goto no_mem; + support = pw_core_get_support(core, &n_support); - handle = calloc(1, factory->size); + if ((res = spa_handle_factory_init(factory, handle, NULL, support, n_support)) < 0) { pw_log_error("can't make factory instance: %d", res); @@ -345,6 +349,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core, spa_handle_clear(handle); init_failed: free(handle); + no_mem: enum_failed: no_symbol: dlclose(hnd); diff --git a/src/modules/spa/spa-node.c b/src/modules/spa/spa-node.c index 1d2e7bdf8..38120fa3f 100644 --- a/src/modules/spa/spa-node.c +++ b/src/modules/spa/spa-node.c @@ -279,7 +279,10 @@ struct pw_node *pw_spa_node_load(struct pw_core *core, support = pw_core_get_support(core, &n_support); - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); + if (handle == NULL) + goto no_mem; + if ((res = spa_handle_factory_init(factory, handle, properties ? &properties->dict : NULL, @@ -319,6 +322,7 @@ struct pw_node *pw_spa_node_load(struct pw_core *core, init_failed: free(handle); enum_failed: + no_mem: no_symbol: dlclose(hnd); open_failed: diff --git a/src/pipewire/loop.c b/src/pipewire/loop.c index 6944125fb..e05cafdc2 100644 --- a/src/pipewire/loop.c +++ b/src/pipewire/loop.c @@ -64,7 +64,7 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties) if (factory == NULL) return NULL; - impl = calloc(1, sizeof(struct impl) + factory->size); + impl = calloc(1, sizeof(struct impl) + spa_handle_factory_get_size(factory, NULL)); if (impl == NULL) return NULL; diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index b66b44eeb..2de855af6 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -107,7 +107,7 @@ load_interface(struct support_info *info, if (factory == NULL) goto not_found; - handle = calloc(1, factory->size); + handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); if ((res = spa_handle_factory_init(factory, handle, NULL, info->support, info->n_support)) < 0) { fprintf(stderr, "can't make factory instance: %d\n", res);