aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_encryption.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-22 20:24:49 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-22 22:57:52 +0200
commit6c39aa87638f7a6f96a97627ac112fb2022bd3a7 (patch)
tree6941498e1cacbd6dcade4a695b27085fa693984f /libqpdf/QPDF_encryption.cc
parent12400475283f5081ea55f52a764e43f14032f6ba (diff)
downloadqpdf-6c39aa87638f7a6f96a97627ac112fb2022bd3a7.tar.zst
In shippable code, favor smart pointers (fixes #235)
Use PointerHolder in several places where manually memory allocation and deallocation were being used. This helps to protect against memory leaks when exceptions are thrown in surprising places.
Diffstat (limited to 'libqpdf/QPDF_encryption.cc')
-rw-r--r--libqpdf/QPDF_encryption.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index d72d6fb7..b5f16e0c 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -204,7 +204,9 @@ iterate_rc4(unsigned char* data, size_t data_len,
unsigned char* okey, int key_len,
int iterations, bool reverse)
{
- unsigned char* key = new unsigned char[QIntC::to_size(key_len)];
+ PointerHolder<unsigned char> key_ph = PointerHolder<unsigned char>(
+ true, new unsigned char[QIntC::to_size(key_len)]);
+ unsigned char* key = key_ph.getPointer();
for (int i = 0; i < iterations; ++i)
{
int const xor_value = (reverse ? iterations - 1 - i : i);
@@ -215,7 +217,6 @@ iterate_rc4(unsigned char* data, size_t data_len,
RC4 rc4(key, QIntC::to_int(key_len));
rc4.process(data, data_len);
}
- delete [] key;
}
static std::string