eina_thread: don't leak on pthread_cancel().
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 17 Sep 2016 01:17:25 +0000 (22:17 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Mon, 19 Sep 2016 04:01:35 +0000 (01:01 -0300)
if we cancel a thread we should still free the context, so use the new
EINA_THREAD_CLEANUP_PUSH() and EINA_THREAD_CLEANUP_POP()

src/lib/eina/eina_thread.c

index f698092..f875504 100644 (file)
@@ -137,6 +137,8 @@ _eina_internal_call(void *context)
    pthread_t self;
 #endif
 
+   EINA_THREAD_CLEANUP_PUSH(free, c);
+
    if (c->prio == EINA_THREAD_BACKGROUND ||
        c->prio == EINA_THREAD_IDLE)
      eina_sched_prio_drop();
@@ -144,13 +146,14 @@ _eina_internal_call(void *context)
 #ifdef EINA_HAVE_DEBUG
    self = pthread_self();
    _eina_debug_thread_add(&self);
+   EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self);
 #endif
    r = c->func((void*) c->data, eina_thread_self());
 #ifdef EINA_HAVE_DEBUG
-   _eina_debug_thread_del(&self);
+   EINA_THREAD_CLEANUP_POP(EINA_TRUE);
 #endif
 
-   free(c);
+   EINA_THREAD_CLEANUP_POP(EINA_TRUE);
 
    return r;
 }