diff --git a/src/libeis-client.c b/src/libeis-client.c index e4dea02..42051e8 100644 --- a/src/libeis-client.c +++ b/src/libeis-client.c @@ -245,6 +245,8 @@ eis_client_disconnect(struct eis_client *client) source_remove(client->source); break; } + + eis_client_unref(client); } static int @@ -596,7 +598,6 @@ eis_client_new(struct eis *eis, int fd) client->id = ++client_id; list_init(&client->devices); - list_append(&eis->clients, &client->link); struct source *s = source_add_autoclose(eis->sink, fd, client_dispatch, client); client->source = source_ref(s); @@ -605,6 +606,8 @@ eis_client_new(struct eis *eis, int fd) if (rc != 0) client = eis_client_unref(client); + eis_add_client(eis, eis_client_ref(client)); + return client; } diff --git a/src/libeis-fd.c b/src/libeis-fd.c index 983f52b..52ef471 100644 --- a/src/libeis-fd.c +++ b/src/libeis-fd.c @@ -84,8 +84,11 @@ eis_backend_fd_add_fd(struct eis *eis, int fd) assert(eis); assert(eis->backend); - if (eis_client_new(eis, fd) != NULL) - return 0; - else + struct eis_client *client = eis_client_new(eis, fd); + if (client == NULL) return -ENOMEM; + + eis_client_unref(client); + + return 0; } diff --git a/src/libeis-private.h b/src/libeis-private.h index 19d06ff..1ba5d59 100644 --- a/src/libeis-private.h +++ b/src/libeis-private.h @@ -114,6 +114,9 @@ eis_client_new(struct eis *eis, int fd); struct eis* eis_client_get_context(struct eis_client *client); +void +eis_add_client(struct eis *eis, struct eis_client *client); + void eis_client_connect_device(struct eis_client *client, struct eis_device *device); diff --git a/src/libeis-socket.c b/src/libeis-socket.c index 12b4642..4276a0f 100644 --- a/src/libeis-socket.c +++ b/src/libeis-socket.c @@ -89,7 +89,8 @@ listener_dispatch(struct source *source, void *data) if (fd == -1) return; - eis_client_new(eis, fd); + struct eis_client *client = eis_client_new(eis, fd); + eis_client_unref(client); } _public_ int diff --git a/src/libeis.c b/src/libeis.c index 23d36fd..1195d50 100644 --- a/src/libeis.c +++ b/src/libeis.c @@ -334,3 +334,9 @@ eis_next_event_type(struct eis *eis) struct eis_event *e = list_first_entry(&eis->event_queue, e, link); return e->type; } + +void +eis_add_client(struct eis *eis, struct eis_client *client) +{ + list_append(&eis->clients, &client->link); +}