Pipewireパッケージ(ちょっと変更)
Revisión | 37b2633756dad1c1f133bf58209df224cca2297b (tree) |
---|---|
Tiempo | 2023-09-30 01:19:13 |
Autor | Barnabás Pőcze <pobrn@prot...> |
Commiter | Barnabás Pőcze |
pulse-server: reorder initialization to make proper cleanup possible
Previously, in case of errors, the struct members were not disposed of
correctly, leading to memory leaks. Reordering the initialization slightly
makes it possible to call impl_free().
See https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1840#note_2106874
@@ -5483,9 +5483,23 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, | ||
5483 | 5483 | const char *str; |
5484 | 5484 | int res = 0; |
5485 | 5485 | |
5486 | + debug_messages = pw_log_topic_enabled(SPA_LOG_LEVEL_INFO, pulse_conn); | |
5487 | + | |
5486 | 5488 | impl = calloc(1, sizeof(*impl) + user_data_size); |
5487 | 5489 | if (impl == NULL) |
5488 | - goto error_exit; | |
5490 | + goto error_free_props; | |
5491 | + | |
5492 | + impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC; | |
5493 | + impl->rate_limit.burst = 1; | |
5494 | + spa_hook_list_init(&impl->hooks); | |
5495 | + spa_list_init(&impl->servers); | |
5496 | + pw_map_init(&impl->samples, 16, 16); | |
5497 | + pw_map_init(&impl->modules, 16, 16); | |
5498 | + spa_list_init(&impl->cleanup_clients); | |
5499 | + spa_list_init(&impl->free_messages); | |
5500 | + | |
5501 | + impl->loop = pw_context_get_main_loop(context); | |
5502 | + impl->work_queue = pw_context_get_work_queue(context); | |
5489 | 5503 | |
5490 | 5504 | if (props == NULL) |
5491 | 5505 | props = pw_properties_new(NULL, NULL); |
@@ -5503,25 +5517,6 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, | ||
5503 | 5517 | pw_properties_set(props, "vm.overrides", NULL); |
5504 | 5518 | } |
5505 | 5519 | |
5506 | - load_defaults(&impl->defs, props); | |
5507 | - | |
5508 | - debug_messages = pw_log_topic_enabled(SPA_LOG_LEVEL_INFO, pulse_conn); | |
5509 | - | |
5510 | - impl->context = context; | |
5511 | - impl->loop = pw_context_get_main_loop(context); | |
5512 | - impl->props = props; | |
5513 | - | |
5514 | - impl->work_queue = pw_context_get_work_queue(context); | |
5515 | - | |
5516 | - spa_hook_list_init(&impl->hooks); | |
5517 | - spa_list_init(&impl->servers); | |
5518 | - impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC; | |
5519 | - impl->rate_limit.burst = 1; | |
5520 | - pw_map_init(&impl->samples, 16, 16); | |
5521 | - pw_map_init(&impl->modules, 16, 16); | |
5522 | - spa_list_init(&impl->cleanup_clients); | |
5523 | - spa_list_init(&impl->free_messages); | |
5524 | - | |
5525 | 5520 | str = pw_properties_get(props, "server.address"); |
5526 | 5521 | if (str == NULL) { |
5527 | 5522 | pw_properties_setf(props, "server.address", |
@@ -5544,8 +5539,6 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, | ||
5544 | 5539 | pw_log_warn("%p: can't create pid file: %s", |
5545 | 5540 | impl, spa_strerror(res)); |
5546 | 5541 | } |
5547 | - pw_context_add_listener(context, &impl->context_listener, | |
5548 | - &context_events, impl); | |
5549 | 5542 | |
5550 | 5543 | #ifdef HAVE_DBUS |
5551 | 5544 | str = pw_properties_get(props, "server.dbus-name"); |
@@ -5554,14 +5547,22 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context, | ||
5554 | 5547 | if (strlen(str) > 0) |
5555 | 5548 | impl->dbus_name = dbus_request_name(context, str); |
5556 | 5549 | #endif |
5550 | + | |
5551 | + load_defaults(&impl->defs, props); | |
5552 | + impl->props = spa_steal_ptr(props); | |
5553 | + | |
5554 | + pw_context_add_listener(context, &impl->context_listener, | |
5555 | + &context_events, impl); | |
5556 | + impl->context = context; | |
5557 | + | |
5557 | 5558 | cmd_run(impl); |
5558 | 5559 | |
5559 | 5560 | return (struct pw_protocol_pulse *) impl; |
5560 | 5561 | |
5561 | 5562 | error_free: |
5562 | - free(impl); | |
5563 | + impl_free(impl); | |
5563 | 5564 | |
5564 | -error_exit: | |
5565 | +error_free_props: | |
5565 | 5566 | pw_properties_free(props); |
5566 | 5567 | |
5567 | 5568 | if (res < 0) |