summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-02-24 03:01:05 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2018-02-24 09:16:09 +0100
commit545af576f2bd9220ba6eebf9d4eb597e2f4992d9 (patch)
treec8d07ebd51d6e6ea3c956802b27eb183700de368 /src/ipcpd
parent2437470c510ad4f9e903c2bc908fa6e6b8f233da (diff)
downloadouroboros-545af576f2bd9220ba6eebf9d4eb597e2f4992d9.tar.gz
ouroboros-545af576f2bd9220ba6eebf9d4eb597e2f4992d9.zip
ipcpd: Fix cleanup of sdu scheduler
Not all threads were cancelled on exit. This fixes (the rather cryptic) error message "The futex facility returned an unexpected error code" when running the stack with the address sanitizer. Also fixes possible double frees when a pthread_create would fail. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/normal/sdu_sched.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/ipcpd/normal/sdu_sched.c b/src/ipcpd/normal/sdu_sched.c
index 0399f4df..d4826ce5 100644
--- a/src/ipcpd/normal/sdu_sched.c
+++ b/src/ipcpd/normal/sdu_sched.c
@@ -100,12 +100,12 @@ struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback)
int i;
int j;
+ assert(callback);
+
sdu_sched = malloc(sizeof(*sdu_sched));
if (sdu_sched == NULL)
goto fail_malloc;
- assert(callback);
-
sdu_sched->callback = callback;
for (i = 0; i < QOS_CUBE_MAX; ++i) {
@@ -135,7 +135,9 @@ struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback)
pthread_cancel(sdu_sched->readers[j]);
for (j = 0; j < i; ++j)
pthread_join(sdu_sched->readers[j], NULL);
- goto fail_pthr;
+ for (j = i; j < QOS_CUBE_MAX * IPCP_SCHED_THR_MUL; ++j)
+ free(infos[i]);
+ goto fail_infos;
}
}
@@ -152,6 +154,7 @@ struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback)
par.sched_priority = min +
(qos_prio[i % QOS_CUBE_MAX] * (max - min) / 99);
+
if (pthread_setschedparam(sdu_sched->readers[i], pol, &par))
goto fail_sched;
}
@@ -163,9 +166,6 @@ struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback)
pthread_cancel(sdu_sched->readers[j]);
for (j = 0; j < QOS_CUBE_MAX * IPCP_SCHED_THR_MUL; ++j)
pthread_join(sdu_sched->readers[j], NULL);
- fail_pthr:
- for (j = 0; j < QOS_CUBE_MAX * IPCP_SCHED_THR_MUL; ++j)
- free(infos[j]);
fail_infos:
for (j = 0; j < QOS_CUBE_MAX; ++j)
fset_destroy(sdu_sched->set[j]);
@@ -181,7 +181,7 @@ void sdu_sched_destroy(struct sdu_sched * sdu_sched)
assert(sdu_sched);
- for (i = 0; i < QOS_CUBE_MAX; ++i) {
+ for (i = 0; i < QOS_CUBE_MAX * IPCP_SCHED_THR_MUL; ++i) {
pthread_cancel(sdu_sched->readers[i]);
pthread_join(sdu_sched->readers[i], NULL);
}