Fix crash on shutdown

Sometimes we insert NULL into the client object map to mark the object
freed. Now that the map also returns those NULL's, don't try to free
them.
Small cleanups
Make some port methods private.
This commit is contained in:
Wim Taymans 2017-09-11 09:48:13 +02:00
parent f03d229467
commit c72d797dde
7 changed files with 40 additions and 34 deletions

View file

@ -58,7 +58,7 @@ parse_line(struct pw_daemon_config *config,
free(local_err);
ret = false;
} else {
spa_list_insert(config->commands.prev, &command->link);
spa_list_append(&config->commands, &command->link);
}
return ret;
@ -194,9 +194,8 @@ bool pw_daemon_config_run_commands(struct pw_daemon_config *config, struct pw_co
}
}
spa_list_for_each_safe(command, tmp, &config->commands, link) {
spa_list_for_each_safe(command, tmp, &config->commands, link)
pw_command_free(command);
}
return ret;
}

View file

@ -181,6 +181,7 @@ void *pw_client_get_user_data(struct pw_client *client)
static void destroy_resource(void *object, void *data)
{
if (object)
pw_resource_destroy(object);
}

View file

@ -153,7 +153,7 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction,
port = pw_map_lookup(portmap, o);
if (n >= ns || o < ids[n]) {
pw_log_debug("node %p: %s port removed %d", node,
pw_log_debug("node %p: %s port %d removed", node,
pw_direction_as_string(direction), o);
if (port != NULL)
@ -161,8 +161,8 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction,
o++;
}
else if (o >= os || (n < ns && o > ids[n])) {
pw_log_debug("node %p: %s port added %d", node,
else if (o >= os || o > ids[n]) {
pw_log_debug("node %p: %s port %d added", node,
pw_direction_as_string(direction), ids[n]);
if (port == NULL)
@ -172,8 +172,8 @@ static void update_port_map(struct pw_node *node, enum pw_direction direction,
n++;
}
else {
pw_log_debug("node %p: %s port unchanged %d", node,
pw_direction_as_string(direction), ids[n]);
pw_log_debug("node %p: %s port %d unchanged", node,
pw_direction_as_string(direction), o);
n++;
o++;
}
@ -719,7 +719,6 @@ struct pw_port *pw_node_get_free_port(struct pw_node *node, enum pw_direction di
port = pw_port_new(direction, port_id, NULL, 0);
if (port == NULL)
goto no_mem;
pw_port_add(port, node);
} else {
port = mixport;

View file

@ -155,7 +155,7 @@ struct pw_port *pw_port_new(enum pw_direction direction,
return NULL;
this = &impl->this;
pw_log_debug("port %p: new", this);
pw_log_debug("port %p: new %s %d", this, pw_direction_as_string(direction), port_id);
if (properties == NULL)
properties = pw_properties_new(NULL, NULL);

View file

@ -81,14 +81,6 @@ struct pw_port_events {
void (*properties_changed) (void *data, const struct pw_properties *properties);
};
/** Create a new port \memberof pw_port
* \return a newly allocated port */
struct pw_port *
pw_port_new(enum pw_direction direction,
uint32_t port_id,
struct pw_properties *properties,
size_t user_data_size);
/** Get the port direction */
enum pw_direction pw_port_get_direction(struct pw_port *port);
@ -110,9 +102,6 @@ void pw_port_add_listener(struct pw_port *port,
const struct pw_port_events *events,
void *data);
/** Get the user data of a port, the size of the memory was given \ref in pw_port_new */
void * pw_port_get_user_data(struct pw_port *port);
#ifdef __cplusplus
}
#endif

View file

@ -372,6 +372,17 @@ struct pw_node_factory {
void *user_data;
};
/** Create a new port \memberof pw_port
* \return a newly allocated port */
struct pw_port *
pw_port_new(enum pw_direction direction,
uint32_t port_id,
struct pw_properties *properties,
size_t user_data_size);
/** Get the user data of a port, the size of the memory was given \ref in pw_port_new */
void * pw_port_get_user_data(struct pw_port *port);
/** Add a port to a node \memberof pw_port */
bool pw_port_add(struct pw_port *port, struct pw_node *node);

View file

@ -18,6 +18,7 @@
*/
#include <stdio.h>
#include <signal.h>
#include <spa/lib/debug.h>
@ -26,8 +27,7 @@
#include <pipewire/type.h>
struct data {
bool running;
struct pw_loop *loop;
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_remote *remote;
@ -355,7 +355,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
switch (state) {
case PW_REMOTE_STATE_ERROR:
printf("remote error: %s\n", error);
data->running = false;
pw_main_loop_quit(data->loop);
break;
case PW_REMOTE_STATE_CONNECTED:
@ -382,28 +382,35 @@ static const struct pw_remote_events remote_events = {
.state_changed = on_state_changed,
};
static void do_quit(void *data, int signal_number)
{
struct data *d = data;
pw_main_loop_quit(d->loop);
}
int main(int argc, char *argv[])
{
struct data data = { 0 };
struct pw_loop *l;
pw_init(&argc, &argv);
data.loop = pw_loop_new(NULL);
data.running = true;
data.core = pw_core_new(data.loop, NULL);
data.loop = pw_main_loop_new(NULL);
l = pw_main_loop_get_loop(data.loop);
pw_loop_add_signal(l, SIGINT, do_quit, &data);
pw_loop_add_signal(l, SIGTERM, do_quit, &data);
data.core = pw_core_new(l, NULL);
data.remote = pw_remote_new(data.core, NULL);
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
pw_remote_connect(data.remote);
pw_loop_enter(data.loop);
while (data.running) {
pw_loop_iterate(data.loop, -1);
}
pw_loop_leave(data.loop);
pw_main_loop_run(data.loop);
pw_remote_destroy(data.remote);
pw_loop_destroy(data.loop);
pw_core_destroy(data.core);
pw_main_loop_destroy(data.loop);
return 0;
}