eina: Fix promise tests and avoid early deletion

- Progress notify refcount fixes, avoiding early deletion
- Avoid leaking memory on tests
This commit is contained in:
Lauro Moura 2016-06-05 16:10:52 -03:00 committed by Felipe Magno de Almeida
parent c6733fbbed
commit b28f6f2fce
2 changed files with 28 additions and 3 deletions

View File

@ -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);
}

View File

@ -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