mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-06-05 14:38:22 +00:00
Always check return status of mutex_(un)lock()
This commit is contained in:
parent
8f5fd31212
commit
bdd7828ca0
|
@ -542,17 +542,22 @@ void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks )
|
||||||
static void *buffer_alloc_malloc_mutexed( size_t len )
|
static void *buffer_alloc_malloc_mutexed( size_t len )
|
||||||
{
|
{
|
||||||
void *buf;
|
void *buf;
|
||||||
mbedtls_mutex_lock( &heap.mutex );
|
if( mbedtls_mutex_lock( &heap.mutex ) != 0 )
|
||||||
|
return( NULL );
|
||||||
buf = buffer_alloc_malloc( len );
|
buf = buffer_alloc_malloc( len );
|
||||||
mbedtls_mutex_unlock( &heap.mutex );
|
if( mbedtls_mutex_unlock( &heap.mutex ) )
|
||||||
|
return( NULL );
|
||||||
return( buf );
|
return( buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buffer_alloc_free_mutexed( void *ptr )
|
static void buffer_alloc_free_mutexed( void *ptr )
|
||||||
{
|
{
|
||||||
mbedtls_mutex_lock( &heap.mutex );
|
/* We have to good option here, but corrupting the heap seems
|
||||||
|
* worse than loosing memory. */
|
||||||
|
if( mbedtls_mutex_lock( &heap.mutex ) )
|
||||||
|
return;
|
||||||
buffer_alloc_free( ptr );
|
buffer_alloc_free( ptr );
|
||||||
mbedtls_mutex_unlock( &heap.mutex );
|
(void) mbedtls_mutex_unlock( &heap.mutex );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_THREADING_C */
|
#endif /* MBEDTLS_THREADING_C */
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,8 @@ int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_lock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
olen = ctx->len;
|
olen = ctx->len;
|
||||||
|
@ -292,7 +293,8 @@ int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_unlock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_unlock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mbedtls_mpi_free( &T );
|
mbedtls_mpi_free( &T );
|
||||||
|
@ -315,7 +317,8 @@ static int rsa_prepare_blinding( mbedtls_rsa_context *ctx, mbedtls_mpi *Vi, mbed
|
||||||
int ret, count = 0;
|
int ret, count = 0;
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_lock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( ctx->Vf.p != NULL )
|
if( ctx->Vf.p != NULL )
|
||||||
|
@ -351,7 +354,8 @@ done:
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_unlock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_unlock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
|
@ -408,7 +412,8 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_lock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_NO_CRT)
|
#if defined(MBEDTLS_RSA_NO_CRT)
|
||||||
|
@ -452,7 +457,8 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_unlock( &ctx->mutex );
|
if( ( ret = mbedtls_mutex_unlock( &ctx->mutex ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
mbedtls_mpi_free( &Vi_copy ); mbedtls_mpi_free( &Vf_copy );
|
mbedtls_mpi_free( &Vi_copy ); mbedtls_mpi_free( &Vf_copy );
|
||||||
#endif
|
#endif
|
||||||
mbedtls_mpi_free( &T ); mbedtls_mpi_free( &T1 ); mbedtls_mpi_free( &T2 );
|
mbedtls_mpi_free( &T ); mbedtls_mpi_free( &T1 ); mbedtls_mpi_free( &T2 );
|
||||||
|
|
Loading…
Reference in a new issue