diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-10-15 07:42:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-15 07:42:57 -0400 |
| commit | 71dd12d08985c31037a74d04ff8b22edb897a265 (patch) | |
| tree | 931024136e3a100a78945223990ddad61ca7f468 | |
| parent | 20b27b067a34732bd79c78afc8164148e066591c (diff) | |
| parent | 6c4b622074dd5a71f351389026604aa81cbe06f3 (diff) | |
Merge pull request #3171 from opensourcerouting/50-memleak-fix
5.0: backport memory leak fix
| -rw-r--r-- | lib/thread.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/thread.c b/lib/thread.c index f9ff16b7b3..b8a1d7388a 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1586,25 +1586,27 @@ void funcname_thread_execute(struct thread_master *m, int (*func)(struct thread *), void *arg, int val, debugargdef) { - struct cpu_thread_history tmp; - struct thread dummy; - - memset(&dummy, 0, sizeof(struct thread)); + struct thread *thread; - pthread_mutex_init(&dummy.mtx, NULL); - dummy.type = THREAD_EVENT; - dummy.add_type = THREAD_EXECUTE; - dummy.master = NULL; - dummy.arg = arg; - dummy.u.val = val; + /* Get or allocate new thread to execute. */ + pthread_mutex_lock(&m->mtx); + { + thread = thread_get(m, THREAD_EVENT, func, arg, debugargpass); - tmp.func = dummy.func = func; - tmp.funcname = dummy.funcname = funcname; - dummy.hist = hash_get(m->cpu_record, &tmp, - (void *(*)(void *))cpu_record_hash_alloc); + /* Set its event value. */ + pthread_mutex_lock(&thread->mtx); + { + thread->add_type = THREAD_EXECUTE; + thread->u.val = val; + thread->ref = &thread; + } + pthread_mutex_unlock(&thread->mtx); + } + pthread_mutex_unlock(&m->mtx); - dummy.schedfrom = schedfrom; - dummy.schedfrom_line = fromln; + /* Execute thread doing all accounting. */ + thread_call(thread); - thread_call(&dummy); + /* Give back or free thread. */ + thread_add_unuse(m, thread); } |
