From f897c97de0b28cc2e48bba1bb9fc986fe4659819 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 27 Aug 2016 23:22:09 +0200 Subject: irmd: Add state checks to api_entry Prevents double destruction. --- src/irmd/api_table.c | 10 +++++++++- src/irmd/api_table.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/irmd/api_table.c b/src/irmd/api_table.c index 2747ed1a..519b4efe 100644 --- a/src/irmd/api_table.c +++ b/src/irmd/api_table.c @@ -70,6 +70,11 @@ void api_entry_destroy(struct api_entry * e) pthread_mutex_lock(&e->state_lock); + if (e->state == API_DESTROY) { + pthread_mutex_unlock(&e->state_lock); + return; + } + if (e->state == API_SLEEP) e->state = API_DESTROY; @@ -163,6 +168,9 @@ int api_entry_sleep(struct api_entry * e) } } + if (e->state == API_DESTROY) + ret = -1; + e->state = API_INIT; pthread_cond_broadcast(&e->state_cond); pthread_mutex_unlock(&e->state_lock); @@ -177,7 +185,7 @@ void api_entry_wake(struct api_entry * e, struct reg_entry * re) pthread_mutex_lock(&e->state_lock); - if (e->state == API_NULL) { + if (e->state != API_SLEEP) { pthread_mutex_unlock(&e->state_lock); return; } diff --git a/src/irmd/api_table.h b/src/irmd/api_table.h index 0758fdb8..8741a86b 100644 --- a/src/irmd/api_table.h +++ b/src/irmd/api_table.h @@ -41,7 +41,7 @@ struct api_entry { pid_t api; char * apn; /* application process instantiated */ char * daf_name; /* DAF this AP-I belongs to */ - struct list_head names; /* names for which this api accepts flows */ + struct list_head names; /* names for which api accepts flows */ struct reg_entry * re; /* reg_entry for which a flow arrived */ -- cgit v1.2.3 From 0c41273687df7aaebf8b749a89d4c2ab328bf4c1 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 27 Aug 2016 23:25:53 +0200 Subject: cdap: Fix destruction Destroying NULL should succeed. Resources need to be freed even if flow_dealloc fails. --- src/lib/cdap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 5dc050a4..df2128a0 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -230,12 +230,10 @@ struct cdap * cdap_create(struct cdap_ops * ops, int cdap_destroy(struct cdap * instance) { if (instance == NULL) - return -1; + return 0; pthread_cancel(instance->reader); - - if (flow_dealloc(instance->fd)) - return -1; + pthread_join(instance->reader, NULL); pthread_mutex_lock(&instance->ids_lock); @@ -243,8 +241,7 @@ int cdap_destroy(struct cdap * instance) pthread_mutex_unlock(&instance->ids_lock); - pthread_join(instance->reader, - NULL); + flow_dealloc(instance->fd); free(instance); -- cgit v1.2.3 From bb2e24baf3f05c03450defd4c22a8a1279698bb1 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 29 Aug 2016 10:46:10 +0200 Subject: lib, cdap: Fix message handler When getting a DELETE opcode, create was called instead of delete. --- src/lib/cdap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/cdap.c b/src/lib/cdap.c index df2128a0..8b1b3bc6 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -107,7 +107,7 @@ static void * handle_cdap_msg(void * o) case OPCODE__DELETE: if (msg->name != NULL && msg->has_value) - instance->ops->cdap_create(instance, + instance->ops->cdap_delete(instance, msg->invoke_id, msg->name, msg->value.data, -- cgit v1.2.3