don't throw exception in destructur when card has been removed

This commit is contained in:
Marc Wäckerlin
2015-09-22 07:42:24 +00:00
parent 99c3b9e115
commit bfd747340a
6 changed files with 165 additions and 87 deletions

View File

@@ -193,6 +193,8 @@ namespace cryptoki {
Library::Init::~Init() {
CRYPTOLOG("log");
/// ignore failure in disconnect, possibly smartcard has
/// been removed
try {
//! calls @c C_Finalize
check(_fn->C_Finalize(0), CRYPTOKI_FN_LOG("C_Finalize"));
@@ -204,8 +206,10 @@ namespace cryptoki {
_lib = 0;
#endif
_fn = 0;
} catch (std::exception& e) {
CRYPTOLOG("unloading cryptoki library failed, reason: "+e.what());
} catch (...) {
if (!std::uncaught_exception()) throw;
CRYPTOLOG("unloading cryptoki library failed");
}
}

View File

@@ -1559,25 +1559,22 @@ namespace cryptoki {
}
~Session() try {
CRYPTOLOG("log "<<(std::uncaught_exception()?"IN EXCEPTION":""));
/// ignore failure in disconnect, possibly smartcard has
/// been removed
try {
logout();
} catch (const std::exception& x) {
CRYPTOLOG("caught: "<<x.what());
close();
if (!std::uncaught_exception()) throw;
} catch (...) {
CRYPTOLOG("caught");
close();
if (!std::uncaught_exception()) throw;
}
close();
} catch (const std::exception& x) {
CRYPTOLOG("caught: "<<x.what());
if (!std::uncaught_exception()) throw;
} catch (...) {
CRYPTOLOG("caught");
if (!std::uncaught_exception()) throw;
}
/*! @name Comfortable Access
@@ -1879,16 +1876,16 @@ namespace cryptoki {
}
~Login() {
/// ignore failure in disconnect, possibly smartcard has
/// been removed
try {
//! calls @c C_Logout
_session.check(_session._slot.library()->C_Logout
(_session._session),
CRYPTOKI_FN_LOG("C_Logout"));
} catch (const std::exception& x) {
if (!std::uncaught_exception()) throw;
CRYPTOLOG("ERROR during error cleanup: "<<x.what());
} catch (...) {
if (!std::uncaught_exception()) throw;
CRYPTOLOG("ERROR during error cleanup.");
}
}

View File

@@ -219,8 +219,8 @@ namespace pcsc {
~Reader() {
CRYPTOLOG("Disconnect Reader");
_state = SCardDisconnect(_id, SCARD_RESET_CARD);
if (!std::uncaught_exception())
_connection->check(_state, "disconnect smartcard");
/// ignore failure in disconnect, possibly smartcard has
/// been removed
}
//! Get reader status.
@@ -495,7 +495,8 @@ namespace pcsc {
~Connection() {
CRYPTOLOG("Close Connection id="<<_id);
_state = SCardReleaseContext(_id);
if (!std::uncaught_exception()) check("smartcard release context");
/// ignore failure in disconnect, possibly smartcard has
/// been removed
}
//! Scans for available readers from a specified list of groups.