From 8e77e8755100c1c055dbca50d4795d165ac0e5c7 Mon Sep 17 00:00:00 2001 From: nils Date: Sun, 5 Feb 2006 19:35:55 +0000 Subject: [PATCH] sc_mutex_destroy should have a return value git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2832 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/card.c | 7 +++++-- src/libopensc/ctbcs.c | 8 ++++++-- src/libopensc/ctx.c | 17 +++++++++++------ src/libopensc/internal.h | 3 ++- src/libopensc/opensc.h | 2 +- src/libopensc/sc.c | 12 +++++++----- src/pkcs11/pkcs11-global.c | 9 ++++++--- 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/libopensc/card.c b/src/libopensc/card.c index 5e21a689..2353e489 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -87,8 +87,11 @@ static void sc_card_free(sc_card_t *card) free(card->ops); if (card->algorithms != NULL) free(card->algorithms); - if (card->mutex != NULL) - sc_mutex_destroy(card->ctx, card->mutex); + if (card->mutex != NULL) { + int r = sc_mutex_destroy(card->ctx, card->mutex); + if (r != SC_SUCCESS) + sc_error(card->ctx, "unable to destroy mutex\n"); + } sc_mem_clear(card, sizeof(*card)); free(card); } diff --git a/src/libopensc/ctbcs.c b/src/libopensc/ctbcs.c index 603dd0cd..35c2ec3a 100644 --- a/src/libopensc/ctbcs.c +++ b/src/libopensc/ctbcs.c @@ -158,7 +158,7 @@ ctbcs_pin_cmd(sc_reader_t *reader, sc_slot_info_t *slot, sc_card_t dummy_card, *card; sc_apdu_t apdu; struct sc_card_operations ops; - int r; + int r, s; switch (data->cmd) { case SC_PIN_CMD_VERIFY: @@ -185,7 +185,11 @@ ctbcs_pin_cmd(sc_reader_t *reader, sc_slot_info_t *slot, card = &dummy_card; r = sc_transmit_apdu(card, &apdu); - sc_mutex_destroy(reader->ctx, card->mutex); + s = sc_mutex_destroy(reader->ctx, card->mutex); + if (s != SC_SUCCESS) { + sc_error(reader->ctx, "unable to destroy mutex\n"); + return s; + } SC_TEST_RET(card->ctx, r, "APDU transmit failed"); /* Check CTBCS status word */ diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c index b1b7a2be..d0eebd76 100644 --- a/src/libopensc/ctx.c +++ b/src/libopensc/ctx.c @@ -746,16 +746,21 @@ int sc_release_context(sc_context_t *ctx) if (drv->atr_map) _sc_free_atr(ctx, drv); } + if (ctx->preferred_language != NULL) + free(ctx->preferred_language); + if (ctx->mutex != NULL) { + int r = sc_mutex_destroy(ctx, ctx->mutex); + if (r != SC_SUCCESS) { + sc_error(ctx, "unable to destroy mutex\n"); + return r; + } + } + if (ctx->conf != NULL) + scconf_free(ctx->conf); if (ctx->debug_file && ctx->debug_file != stdout) fclose(ctx->debug_file); if (ctx->error_file && ctx->error_file != stderr) fclose(ctx->error_file); - if (ctx->preferred_language != NULL) - free(ctx->preferred_language); - if (ctx->conf != NULL) - scconf_free(ctx->conf); - if (ctx->mutex != NULL) - sc_mutex_destroy(ctx, ctx->mutex); if (ctx->app_name != NULL) free(ctx->app_name); sc_mem_clear(ctx, sizeof(*ctx)); diff --git a/src/libopensc/internal.h b/src/libopensc/internal.h index ef8512e4..141d495a 100644 --- a/src/libopensc/internal.h +++ b/src/libopensc/internal.h @@ -148,8 +148,9 @@ int sc_mutex_unlock(const sc_context_t *ctx, void *mutex); * SC_SUCCESS. * @param ctx sc_context_t object with the thread context * @param mutex mutex object to be destroyed + * @return SC_SUCCESS on success and an error code otherwise */ -void sc_mutex_destroy(const sc_context_t *ctx, void *mutex); +int sc_mutex_destroy(const sc_context_t *ctx, void *mutex); /** * Returns a unique id for every thread. * @param ctx sc_context_t object with the thread context diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index 90598dc3..74af06af 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -629,7 +629,7 @@ typedef struct { /** unlocks a mutex object */ int (*unlock_mutex)(void *); /** destroys a mutex object */ - void (*destroy_mutex)(void *); + int (*destroy_mutex)(void *); /** returns unique identifier for the thread (can be NULL) */ unsigned long (*thread_id)(void); } sc_thread_context_t; diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index 12f69f60..415155c3 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -705,12 +705,14 @@ int sc_mutex_unlock(const sc_context_t *ctx, void *mutex) return SC_SUCCESS; } -void sc_mutex_destroy(const sc_context_t *ctx, void *mutex) +int sc_mutex_destroy(const sc_context_t *ctx, void *mutex) { - if (ctx == NULL || ctx->thread_ctx == NULL || - ctx->thread_ctx->destroy_mutex == NULL) - return; - ctx->thread_ctx->destroy_mutex(mutex); + if (ctx == NULL) + return SC_ERROR_INVALID_ARGUMENTS; + if (ctx->thread_ctx != NULL && ctx->thread_ctx->destroy_mutex != NULL) + return ctx->thread_ctx->destroy_mutex(mutex); + else + return SC_SUCCESS; } unsigned long sc_thread_id(const sc_context_t *ctx) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index ea17af96..04c0fed7 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -151,11 +151,14 @@ static int sc_unlock_mutex(void *m) } -static void sc_destroy_mutex(void *m) +static int sc_destroy_mutex(void *m) { if (_locking == NULL) - return; - _locking->DestroyMutex(m); + return SC_SUCCESS; + if (_locking->DestroyMutex(m) == CKR_OK) + return SC_SUCCESS; + else + return SC_ERROR_INTERNAL; } static sc_thread_context_t sc_thread_ctx = {