diff options
Diffstat (limited to 'src/lib/openjp2/thread.c')
| -rw-r--r-- | src/lib/openjp2/thread.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lib/openjp2/thread.c b/src/lib/openjp2/thread.c index fce563d0..79a9d5fb 100644 --- a/src/lib/openjp2/thread.c +++ b/src/lib/openjp2/thread.c @@ -314,11 +314,13 @@ struct opj_mutex_t opj_mutex_t* opj_mutex_create(void) { - opj_mutex_t* mutex = (opj_mutex_t*) opj_malloc(sizeof(opj_mutex_t)); - if( !mutex ) - return NULL; - pthread_mutex_t pthr_mutex = PTHREAD_MUTEX_INITIALIZER; - mutex->mutex = pthr_mutex; + opj_mutex_t* mutex = (opj_mutex_t*) opj_calloc(1U, sizeof(opj_mutex_t)); + if( mutex != NULL ) { + if ( pthread_mutex_init(&mutex->mutex, NULL) != 0) { + opj_free(mutex); + mutex = NULL; + } + } return mutex; } @@ -537,19 +539,24 @@ OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, opj_tls_free_func opj { opj_tls_key_val_t* new_key_val; int i; + + if (tls->key_val_count == INT_MAX) { + return OPJ_FALSE; + } for(i=0;i<tls->key_val_count;i++) { if( tls->key_val[i].key == key ) { - if( tls->key_val[i].opj_free_func ) + if( tls->key_val[i].opj_free_func ) { tls->key_val[i].opj_free_func(tls->key_val[i].value); + } tls->key_val[i].value = value; tls->key_val[i].opj_free_func = opj_free_func; return OPJ_TRUE; } } new_key_val = (opj_tls_key_val_t*) opj_realloc( tls->key_val, - (tls->key_val_count + 1) * sizeof(opj_tls_key_val_t) ); + ((size_t)tls->key_val_count + 1U) * sizeof(opj_tls_key_val_t) ); if( !new_key_val ) return OPJ_FALSE; tls->key_val = new_key_val; @@ -691,7 +698,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) if( tp->cond == NULL ) return OPJ_FALSE; - tp->worker_threads = (opj_worker_thread_t*) opj_calloc( num_threads, + tp->worker_threads = (opj_worker_thread_t*) opj_calloc( (size_t)num_threads, sizeof(opj_worker_thread_t) ); if( tp->worker_threads == NULL ) return OPJ_FALSE; |
