Merge pull request #15645 from SimonWalton-HiFi/wallet-signwithkey-memleak

Fix minor memory leak using unique_ptr
This commit is contained in:
Clément Brisset 2019-05-29 14:38:42 -07:00 committed by GitHub
commit abce60e356
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -654,7 +654,7 @@ QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
EC_KEY* ecPrivateKey = NULL;
if ((ecPrivateKey = readPrivateKey(keyFilePath()))) {
unsigned char* sig = new unsigned char[ECDSA_size(ecPrivateKey)];
const auto sig = std::make_unique<unsigned char[]>(ECDSA_size(ecPrivateKey));
unsigned int signatureBytes = 0;
@ -663,10 +663,10 @@ QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
QByteArray hashedPlaintext = QCryptographicHash::hash(text, QCryptographicHash::Sha256);
int retrn = ECDSA_sign(0, reinterpret_cast<const unsigned char*>(hashedPlaintext.constData()), hashedPlaintext.size(),
sig, &signatureBytes, ecPrivateKey);
sig.get(), &signatureBytes, ecPrivateKey);
EC_KEY_free(ecPrivateKey);
QByteArray signature(reinterpret_cast<const char*>(sig), signatureBytes);
QByteArray signature(reinterpret_cast<const char*>(sig.get()), signatureBytes);
if (retrn != -1) {
return signature.toBase64();
}