diff --git a/channels/smartcard/client/smartcard_main.c b/channels/smartcard/client/smartcard_main.c index 4c3906373..7c63d7e26 100644 --- a/channels/smartcard/client/smartcard_main.c +++ b/channels/smartcard/client/smartcard_main.c @@ -140,15 +140,13 @@ static DWORD WINAPI smartcard_context_thread(LPVOID arg) error = smartcard_complete_irp(smartcard, element->irp, &handled); if (!handled) element->irp->Discard(element->irp); + smartcard_operation_free(&element->operation, TRUE); if (error) { - smartcard_operation_free(&element->operation, TRUE); WLog_ERR(TAG, "Queue_Enqueue failed!"); break; } - - smartcard_operation_free(&element->operation, TRUE); } } } diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 08334c69e..138c1d7cd 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -2873,7 +2873,10 @@ static LONG WINAPI PCSC_SCardWriteCacheA(SCARDCONTEXT hContext, UUID* CardIdenti memcpy(data->data, Data, data->len); HashTable_Remove(ctx->cache, id); - if (!HashTable_Insert(ctx->cache, id, data)) + const BOOL rc = HashTable_Insert(ctx->cache, id, data); + free(id); + + if (!rc) { pcsc_cache_item_free(data); return SCARD_E_NO_MEMORY; @@ -2915,11 +2918,15 @@ static LONG WINAPI PCSC_SCardWriteCacheW(SCARDCONTEXT hContext, UUID* CardIdenti memcpy(data->data, Data, data->len); HashTable_Remove(ctx->cache, id); - if (!HashTable_Insert(ctx->cache, id, data)) + const BOOL rc = HashTable_Insert(ctx->cache, id, data); + free(id); + + if (!rc) { pcsc_cache_item_free(data); return SCARD_E_NO_MEMORY; } + return SCARD_S_SUCCESS; }