summaryrefslogtreecommitdiff
path: root/src/irmd/registry.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-07-15 15:49:23 +0200
committerdimitri staessens <[email protected]>2016-07-15 15:49:23 +0200
commite14d0da88d4f3fcd0c19c231b59d31189c4d71ad (patch)
tree936e0f4857a48a4be17087c2d32b754b09433747 /src/irmd/registry.c
parent71956f22abec7bb15f6bfc52b4168ff85499eea1 (diff)
downloadouroboros-e14d0da88d4f3fcd0c19c231b59d31189c4d71ad.tar.gz
ouroboros-e14d0da88d4f3fcd0c19c231b59d31189c4d71ad.zip
irmd: Fix accessing reg_api struct after destroy
The destroy now only frees after all threads stopped using the object. Also fixes a SEGV when trying to allocate a flow to a remote name.
Diffstat (limited to 'src/irmd/registry.c')
-rw-r--r--src/irmd/registry.c49
1 files changed, 14 insertions, 35 deletions
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index f688e1cc..32741460 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -63,7 +63,7 @@ struct reg_api * reg_api_create(pid_t api)
i->state = REG_I_WAKE;
pthread_mutex_init(&i->mutex, NULL);
- pthread_cond_init(&i->wakeup, NULL);
+ pthread_cond_init(&i->cond_state, NULL);
INIT_LIST_HEAD(&i->next);
@@ -72,21 +72,18 @@ struct reg_api * reg_api_create(pid_t api)
void reg_api_destroy(struct reg_api * i)
{
- bool wait = true;
pthread_mutex_lock(&i->mutex);
- i->state = REG_I_NULL;
- pthread_cond_broadcast(&i->wakeup);
+ if (i->state != REG_I_SLEEP)
+ i->state = REG_I_WAKE;
+ else
+ i->state = REG_I_NULL;
+
+ pthread_cond_broadcast(&i->cond_state);
pthread_mutex_unlock(&i->mutex);
- while (wait) {
- pthread_mutex_lock(&i->mutex);
- if (pthread_cond_destroy(&i->wakeup))
- pthread_cond_broadcast(&i->wakeup);
- else
- wait = false;
- pthread_mutex_unlock(&i->mutex);
- }
+ while (i->state != REG_I_WAKE)
+ ;
pthread_mutex_destroy(&i->mutex);
@@ -107,7 +104,10 @@ void reg_api_sleep(struct reg_api * i)
(void *) &i->mutex);
while (i->state == REG_I_SLEEP)
- pthread_cond_wait(&i->wakeup, &i->mutex);
+ pthread_cond_wait(&i->cond_state, &i->mutex);
+
+ i->state = REG_I_WAKE;
+ pthread_cond_signal(&i->cond_state);
pthread_cleanup_pop(true);
}
@@ -123,7 +123,7 @@ void reg_api_wake(struct reg_api * i)
i->state = REG_I_WAKE;
- pthread_cond_signal(&i->wakeup);
+ pthread_cond_signal(&i->cond_state);
pthread_mutex_unlock(&i->mutex);
}
@@ -674,27 +674,6 @@ char * registry_get_dif_for_dst(struct list_head * registry,
return NULL;
} else {
LOG_DBGF("No local ap %s found.", dst_name);
- list_for_each(pos, &re->difs) {
- struct reg_dif * rd =
- list_entry(pos, struct reg_dif, next);
- if (rd->type == IPCP_NORMAL)
- return rd->dif_name;
- }
-
- list_for_each(pos, &re->difs) {
- struct reg_dif * rd =
- list_entry(pos, struct reg_dif, next);
- if (rd->type == IPCP_SHIM_ETH_LLC)
- return rd->dif_name;
- }
-
- list_for_each(pos, &re->difs) {
- struct reg_dif * rd =
- list_entry(pos, struct reg_dif, next);
- if (rd->type == IPCP_SHIM_UDP)
- return rd->dif_name;
- }
-
return NULL;
}
}