From: Martin Quinson Date: Sun, 17 Apr 2016 12:23:53 +0000 (+0200) Subject: plug a memleak in Threaded maestro creation X-Git-Tag: v3_13~85 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4307004096e8d32385e4cf451a52bbef1a46d95e plug a memleak in Threaded maestro creation --- diff --git a/src/simix/ThreadContext.cpp b/src/simix/ThreadContext.cpp index 91857d8196..722ff30f60 100644 --- a/src/simix/ThreadContext.cpp +++ b/src/simix/ThreadContext.cpp @@ -98,11 +98,9 @@ ThreadContext::ThreadContext(std::function code, void_pfn_smxprocess_t cleanup, smx_process_t process, bool maestro) : AttachContext(std::move(code), cleanup, process) { - // We do not need the semaphores when maestro is in main: - // if (!(maestro && !code)) { - this->begin_ = xbt_os_sem_init(0); - this->end_ = xbt_os_sem_init(0); - // } + // We do not need the semaphores when maestro is in main, but we create them anyway for simplicity wrt the case where maestro is externalized + this->begin_ = xbt_os_sem_init(0); + this->end_ = xbt_os_sem_init(0); /* If the user provided a function for the process then use it */ if (has_code()) { @@ -130,15 +128,12 @@ ThreadContext::ThreadContext(std::function code, ThreadContext::~ThreadContext() { - /* check if this is the context of maestro (it doesn't have a real thread) */ - if (this->thread_) { - /* wait about the thread terminason */ + if (this->thread_) /* If there is a thread (maestro don't have any), wait for its termination */ xbt_os_thread_join(this->thread_, nullptr); - /* destroy the synchronisation objects */ - xbt_os_sem_destroy(this->begin_); - xbt_os_sem_destroy(this->end_); - } + /* destroy the synchronization objects */ + xbt_os_sem_destroy(this->begin_); + xbt_os_sem_destroy(this->end_); } void *ThreadContext::wrapper(void *param)