aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_RC4.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/Pl_RC4.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/Pl_RC4.cc')
-rw-r--r--libqpdf/Pl_RC4.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc
index 407490ca..6c8fd3c6 100644
--- a/libqpdf/Pl_RC4.cc
+++ b/libqpdf/Pl_RC4.cc
@@ -8,19 +8,18 @@ Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
out_bufsize(out_bufsize),
rc4(key_data, key_len)
{
- this->outbuf = new unsigned char[out_bufsize];
+ this->outbuf = PointerHolder<unsigned char>(
+ true, new unsigned char[out_bufsize]);
}
Pl_RC4::~Pl_RC4()
{
- delete [] this->outbuf;
- this->outbuf = 0;
}
void
Pl_RC4::write(unsigned char* data, size_t len)
{
- if (this->outbuf == 0)
+ if (this->outbuf.getPointer() == 0)
{
throw std::logic_error(
this->identifier +
@@ -35,16 +34,15 @@ Pl_RC4::write(unsigned char* data, size_t len)
size_t bytes =
(bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
bytes_left -= bytes;
- rc4.process(p, bytes, outbuf);
+ rc4.process(p, bytes, outbuf.getPointer());
p += bytes;
- getNext()->write(outbuf, bytes);
+ getNext()->write(outbuf.getPointer(), bytes);
}
}
void
Pl_RC4::finish()
{
- delete [] this->outbuf;
this->outbuf = 0;
this->getNext()->finish();
}