Fixing memory leaks in the encryption module
authorIvan Čukić <ivan.cukic@kde.org>
Sun, 5 May 2019 20:24:12 +0000 (22:24 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Tue, 2 Jun 2020 14:09:06 +0000 (14:09 +0000)
commitc31b1a750d68fa556154a5eee65b2d6370e8a19b
tree3d501366bddc14c83e52d6b3916ea9ae9f362945
parent5a1404ef59141cd26d8b416b9b64cbebb06f0b32
Fixing memory leaks in the encryption module

Due to usage of early-returns, combined with malloc/free,
several buffers that get allocated are leaked when an error
occurs.

Several functions had potential leaks:

 - `encryptStringSymmetric` leaked `ctext`
 - `EncryptionHelper::fileDecryption` leaked `out`
 - `EncryptionHelper::fileEncryption` leaked `out`

Most of the functions had leaks of the cypher context.

This patch uses `QByteArray` as the handler for the dynamically
allocated buffers for openssl to operate on. This also removes
the need for conversions from malloc'd buffers to `QByteArray`
variables previously present in the code.

It also introduces a `CypherCtx` thin wrapper class to provide
a leak-free handling of `EVP_CIPHER_CTX`.
src/libsync/clientsideencryption.cpp