felipealmeida pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=b28f6f2fce202cf90c7f9f01d19b28971eb6021d
commit b28f6f2fce202cf90c7f9f01d19b28971eb6021d Author: Lauro Moura <lauromo...@expertisesolutions.com.br> Date: Sun Jun 5 16:10:52 2016 -0300 eina: Fix promise tests and avoid early deletion - Progress notify refcount fixes, avoiding early deletion - Avoid leaking memory on tests --- src/lib/eina/eina_promise.c | 9 ++++++--- src/tests/eina/eina_test_promise.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/lib/eina/eina_promise.c b/src/lib/eina/eina_promise.c index e6db032..3410048 100644 --- a/src/lib/eina/eina_promise.c +++ b/src/lib/eina/eina_promise.c @@ -409,7 +409,6 @@ _eina_promise_progress_cb_add(_Eina_Promise_Default* promise, Eina_Promise_Progr cb->data = data; cb->free = free_cb; promise->progress_callbacks = eina_inlist_append(promise->progress_callbacks, EINA_INLIST_GET(cb)); - EINA_INLIST_FOREACH(owner->promise.progress_notify_callbacks, notify_data) { (*notify_data->callback)(notify_data->data, &owner->owner_vtable); @@ -759,6 +758,8 @@ static void _eina_promise_progress_notify_fulfilled(void* data, Eina_Promise_Owner* p EINA_UNUSED) { Eina_Promise_Owner* owner = data; + // Make sure the promise is alive after value_set until our cleanup cp is called + eina_promise_ref(eina_promise_owner_promise_get(owner)); eina_promise_owner_value_set(owner, NULL, NULL); } @@ -767,11 +768,13 @@ EAPI Eina_Error EINA_ERROR_PROMISE_CANCEL; EAPI Eina_Error EINA_ERROR_PROMISE_NULL; static void -_eina_promise_progress_notify_failed(void* data) +_eina_promise_progress_notify_finish(void* data) { Eina_Promise_Owner* owner = data; if(eina_promise_owner_pending_is(owner)) eina_promise_owner_error_set(owner, EINA_ERROR_PROMISE_NO_NOTIFY); + else // Cleanup the ref we got from the fulfilled cb + eina_promise_unref(eina_promise_owner_promise_get(owner)); } EAPI Eina_Promise* @@ -782,7 +785,7 @@ eina_promise_progress_notification(Eina_Promise_Owner* promise) owner = eina_promise_value_add(0); eina_promise_owner_progress_notify(promise, &_eina_promise_progress_notify_fulfilled, owner, - &_eina_promise_progress_notify_failed); + &_eina_promise_progress_notify_finish); return eina_promise_owner_promise_get(owner); } diff --git a/src/tests/eina/eina_test_promise.c b/src/tests/eina/eina_test_promise.c index 8df6e26..e2ef1f3 100644 --- a/src/tests/eina/eina_test_promise.c +++ b/src/tests/eina/eina_test_promise.c @@ -231,6 +231,9 @@ START_TEST(eina_test_promise_progress) ck_assert(progress_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -258,6 +261,9 @@ START_TEST(eina_test_promise_progress_notify1) ck_assert(progress_notify_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -279,6 +285,8 @@ START_TEST(eina_test_promise_progress_notify2) ck_assert(progress_notify_ran); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -315,6 +323,9 @@ START_TEST(eina_test_promise_progress_notify3) ck_assert(progress_notify_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -517,6 +528,9 @@ START_TEST(eina_test_pointer_promise_progress) ck_assert(progress_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -538,6 +552,9 @@ START_TEST(eina_test_pointer_promise_progress_notify1) ck_assert(progress_notify_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -559,6 +576,8 @@ START_TEST(eina_test_pointer_promise_progress_notify2) ck_assert(progress_notify_ran); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST @@ -583,6 +602,9 @@ START_TEST(eina_test_pointer_promise_progress_notify3) ck_assert(progress_notify_ran); + eina_promise_unref(promise); + eina_promise_owner_value_set(owner, NULL, NULL); + eina_shutdown(); } END_TEST --