Fix the sources ref handling again

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-07 09:41:37 +10:00
parent e860d24763
commit d017eb1a91
2 changed files with 11 additions and 5 deletions

View file

@ -51,6 +51,7 @@ eis_socket(struct eis *eis)
static inline void
eis_socket_destroy(struct eis_socket *socket)
{
source_remove(socket->listener);
socket->listener = source_unref(socket->listener);
if (socket->socketpath) {
unlink(socket->socketpath);
@ -129,7 +130,8 @@ eis_setup_backend_socket(struct eis *eis, const char *socketpath)
if (listen(sockfd, 2) == -1)
return -errno;
source_add_autoclose(eis->sink, sockfd, listener_dispatch, eis_socket);
struct source *s = source_add_autoclose(eis->sink, sockfd, listener_dispatch, eis_socket);
eis_socket->listener = source_ref(s);
eis_socket->socketpath = steal(&path);
eis->backend = steal(&eis_socket);
eis->backend_interface = interface;

View file

@ -73,10 +73,13 @@ source_remove(struct source *source)
if (source->close_behavior == SOURCE_CLOSE_FD_ON_REMOVE)
source->fd = xclose(source->fd);
}
/* Note: epollfd was the owner of the source, new owner is the removed
list */
list_remove(&source->link);
list_append(&source->sink->sources_removed, &source->link);
if (!list_empty(&source->link)) {
list_remove(&source->link);
/* Note: epollfd was the owner of the source, new owner is
* the removed list */
list_append(&source->sink->sources_removed, &source->link);
}
}
/* Ignore, use source_unref() */
@ -187,6 +190,7 @@ sink_dispatch(struct sink *sink)
struct source *s, *tmp;
list_for_each_safe(s, tmp, &sink->sources_removed, link) {
list_remove(&s->link);
list_init(&s->link);
source_unref(s);
}