Skip to content

Commit

Permalink
fix memory issue ibetween list of token slots and the libp11 context
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Jun 14, 2024
1 parent 5c7042c commit 39ff954
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,12 @@ void ClientSideEncryption::initializeHardwareTokenEncryption(QWidget *settingsDi
return;
}

auto deleter = [&ctx, tokensCount] (PKCS11_SLOT* pointer) noexcept -> void {
auto deleter = [ctx = static_cast<PKCS11_CTX*>(ctx), tokensCount] (PKCS11_SLOT* pointer) noexcept -> void {
qCWarning(lcCse()) << "destructor" << pointer << ctx;
PKCS11_release_all_slots(ctx, pointer, tokensCount);
if (pointer) {
qCWarning(lcCse()) << "destructor" << pointer << ctx;
PKCS11_release_all_slots(ctx, pointer, tokensCount);
}
};

auto tokenSlots = decltype(_tokenSlots){tempTokenSlots, deleter};
Expand Down Expand Up @@ -1190,8 +1193,8 @@ void ClientSideEncryption::initializeHardwareTokenEncryption(QWidget *settingsDi

emit initializationFinished();

_context = std::move(ctx);
_tokenSlots = std::move(tokenSlots);
_context = std::move(ctx);

return;
}
Expand Down Expand Up @@ -1693,7 +1696,8 @@ void ClientSideEncryption::forgetSensitiveData(const AccountPtr &account)
_usbTokenInformation.setSha256Fingerprint({});
account->setEncryptionCertificateFingerprint({});
_encryptionCertificate.clear();
//_tokenSlots.reset();
_otherCertificates.clear();
_tokenSlots.reset();
_context = Pkcs11Context{Pkcs11Context::State::EmptyContext};
Q_EMIT canDecryptChanged();
Q_EMIT canEncryptChanged();
Expand Down Expand Up @@ -2918,6 +2922,7 @@ void CertificateInformation::clear()
{
_hardwarePublicKey = nullptr;
_hardwarePrivateKey = nullptr;
_privateKeyData.clear();
_certificate.clear();
_certificateExpired = true;
_certificateNotYetValid = true;
Expand Down
1 change: 0 additions & 1 deletion src/libsync/clientsideencryptionprimitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class Pkcs11Context {

Pkcs11Context(const Pkcs11Context&) = delete;


~Pkcs11Context();

Pkcs11Context& operator=(Pkcs11Context &&otherContext);
Expand Down

0 comments on commit 39ff954

Please sign in to comment.