forked from enlightenment/efl
eina: ensure resource destruction on failure
In case of failure within eina_lock_new() (posix), a pthread_mutexattr_t would have been left in an initialized state, without any deinitialization being called. Consequences would have been implementation defined.
This commit is contained in:
parent
109d040e3d
commit
dec1d251dc
|
@ -169,6 +169,7 @@ static inline Eina_Bool
|
|||
eina_lock_new(Eina_Lock *mutex)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
Eina_Bool ok = EINA_FALSE;
|
||||
|
||||
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||
if (!_eina_threads_activated)
|
||||
|
@ -181,15 +182,16 @@ eina_lock_new(Eina_Lock *mutex)
|
|||
feature for sure with that change. */
|
||||
#ifdef EINA_HAVE_DEBUG_THREADS
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) != 0)
|
||||
return EINA_FALSE;
|
||||
goto fail_release;
|
||||
memset(mutex, 0, sizeof(Eina_Lock));
|
||||
#endif
|
||||
if (pthread_mutex_init(&(mutex->mutex), &attr) != 0)
|
||||
return EINA_FALSE;
|
||||
goto fail_release;
|
||||
|
||||
ok = EINA_TRUE;
|
||||
fail_release:
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
return EINA_TRUE;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
Loading…
Reference in New Issue