fix crashes and leaks on shutdown

This commit is contained in:
Wim Taymans 2017-10-17 10:14:56 +02:00
parent f817aabe24
commit 323c644084
5 changed files with 27 additions and 5 deletions

View file

@ -686,9 +686,9 @@ static int impl_clear(struct spa_handle *handle)
impl = (struct impl *) handle; impl = (struct impl *) handle;
spa_list_for_each_safe(source, tmp, &impl->source_list, link) spa_list_for_each_safe(source, tmp, &impl->source_list, link)
loop_destroy_source(&source->source); loop_destroy_source(&source->source);
spa_list_for_each_safe(source, tmp, &impl->destroy_list, link) spa_list_for_each_safe(source, tmp, &impl->destroy_list, link)
free(source); free(source);
close(impl->ack_fd); close(impl->ack_fd);
close(impl->epoll_fd); close(impl->epoll_fd);

View file

@ -137,7 +137,7 @@ static bool refill_buffer(struct pw_protocol_native_connection *conn, struct buf
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf; msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf); msg.msg_controllen = sizeof(cmsgbuf);
msg.msg_flags = MSG_CMSG_CLOEXEC; msg.msg_flags = MSG_CMSG_CLOEXEC | MSG_DONTWAIT;
while (true) { while (true) {
len = recvmsg(conn->fd, &msg, msg.msg_flags); len = recvmsg(conn->fd, &msg, msg.msg_flags);
@ -482,7 +482,7 @@ bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *c
} }
while (true) { while (true) {
len = sendmsg(conn->fd, &msg, MSG_NOSIGNAL); len = sendmsg(conn->fd, &msg, MSG_NOSIGNAL | MSG_DONTWAIT);
if (len < 0) { if (len < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;

View file

@ -486,13 +486,21 @@ void pw_core_destroy(struct pw_core *core)
{ {
struct pw_global *global, *t; struct pw_global *global, *t;
struct pw_module *module, *tm; struct pw_module *module, *tm;
struct pw_remote *remote, *tr;
struct pw_node *node, *tn;
pw_log_debug("core %p: destroy", core); pw_log_debug("core %p: destroy", core);
spa_hook_list_call(&core->listener_list, struct pw_core_events, destroy); spa_hook_list_call(&core->listener_list, struct pw_core_events, destroy);
spa_list_for_each_safe(remote, tr, &core->remote_list, link)
pw_remote_destroy(remote);
spa_list_for_each_safe(module, tm, &core->module_list, link) spa_list_for_each_safe(module, tm, &core->module_list, link)
pw_module_destroy(module); pw_module_destroy(module);
spa_list_for_each_safe(node, tn, &core->node_list, link)
pw_node_destroy(node);
spa_list_for_each_safe(global, t, &core->global_list, link) spa_list_for_each_safe(global, t, &core->global_list, link)
pw_global_destroy(global); pw_global_destroy(global);

View file

@ -201,6 +201,9 @@ void pw_init(int *argc, char **argv[])
if ((str = getenv("SPA_PLUGIN_DIR")) == NULL) if ((str = getenv("SPA_PLUGIN_DIR")) == NULL)
str = PLUGINDIR; str = PLUGINDIR;
if (support_info.n_support > 0)
return;
if (open_support(str, "support/libspa-support", &support_info)) if (open_support(str, "support/libspa-support", &support_info))
configure_support(&support_info); configure_support(&support_info);
} }

View file

@ -518,6 +518,8 @@ static void clean_transport(struct pw_proxy *proxy)
if (data->trans == NULL) if (data->trans == NULL)
return; return;
unhandle_socket(proxy);
spa_list_for_each(port, &data->node->input_ports, link) { spa_list_for_each(port, &data->node->input_ports, link) {
spa_graph_port_remove(&data->in_ports[port->port_id].output); spa_graph_port_remove(&data->in_ports[port->port_id].output);
spa_graph_port_remove(&data->in_ports[port->port_id].input); spa_graph_port_remove(&data->in_ports[port->port_id].input);
@ -530,7 +532,6 @@ static void clean_transport(struct pw_proxy *proxy)
free(data->in_ports); free(data->in_ports);
free(data->out_ports); free(data->out_ports);
pw_client_node_transport_destroy(data->trans); pw_client_node_transport_destroy(data->trans);
unhandle_socket(proxy);
close(data->rtwritefd); close(data->rtwritefd);
data->trans = NULL; data->trans = NULL;
@ -1056,6 +1057,15 @@ static void do_node_init(struct pw_proxy *proxy)
pw_client_node_proxy_done(data->node_proxy, 0, SPA_RESULT_OK); pw_client_node_proxy_done(data->node_proxy, 0, SPA_RESULT_OK);
} }
static void node_destroy(void *data)
{
struct node_data *d = data;
pw_log_debug("%p: destroy", d);
pw_client_node_proxy_destroy(d->node_proxy);
pw_proxy_destroy((struct pw_proxy *)d->node_proxy);
d->node_proxy = NULL;
}
static void node_active_changed(void *data, bool active) static void node_active_changed(void *data, bool active)
{ {
struct node_data *d = data; struct node_data *d = data;
@ -1065,6 +1075,7 @@ static void node_active_changed(void *data, bool active)
static const struct pw_node_events node_events = { static const struct pw_node_events node_events = {
PW_VERSION_NODE_EVENTS, PW_VERSION_NODE_EVENTS,
.destroy = node_destroy,
.active_changed = node_active_changed, .active_changed = node_active_changed,
.need_input = node_need_input, .need_input = node_need_input,
.have_output = node_have_output, .have_output = node_have_output,