aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_PNGFilter.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_PNGFilter.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_PNGFilter.cc')
-rw-r--r--libqpdf/Pl_PNGFilter.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc
index a39c17f9..6a3bc5b8 100644
--- a/libqpdf/Pl_PNGFilter.cc
+++ b/libqpdf/Pl_PNGFilter.cc
@@ -45,12 +45,14 @@ Pl_PNGFilter::Pl_PNGFilter(char const* identifier, Pipeline* next,
"PNGFilter created with invalid columns value");
}
this->bytes_per_row = bpr & UINT_MAX;
- this->buf1 = new unsigned char[this->bytes_per_row + 1];
- this->buf2 = new unsigned char[this->bytes_per_row + 1];
- memset(this->buf1, 0, this->bytes_per_row + 1);
- memset(this->buf2, 0, this->bytes_per_row + 1);
- this->cur_row = this->buf1;
- this->prev_row = this->buf2;
+ this->buf1 = PointerHolder<unsigned char>(
+ true, new unsigned char[this->bytes_per_row + 1]);
+ this->buf2 = PointerHolder<unsigned char>(
+ true, new unsigned char[this->bytes_per_row + 1]);
+ memset(this->buf1.getPointer(), 0, this->bytes_per_row + 1);
+ memset(this->buf2.getPointer(), 0, this->bytes_per_row + 1);
+ this->cur_row = this->buf1.getPointer();
+ this->prev_row = this->buf2.getPointer();
// number of bytes per incoming row
this->incoming = (action == a_encode ?
@@ -60,8 +62,6 @@ Pl_PNGFilter::Pl_PNGFilter(char const* identifier, Pipeline* next,
Pl_PNGFilter::~Pl_PNGFilter()
{
- delete [] buf1;
- delete [] buf2;
}
void
@@ -81,7 +81,7 @@ Pl_PNGFilter::write(unsigned char* data, size_t len)
// Swap rows
unsigned char* t = this->prev_row;
this->prev_row = this->cur_row;
- this->cur_row = t ? t : this->buf2;
+ this->cur_row = t ? t : this->buf2.getPointer();
memset(this->cur_row, 0, this->bytes_per_row + 1);
left = this->incoming;
this->pos = 0;
@@ -269,7 +269,7 @@ Pl_PNGFilter::finish()
processRow();
}
this->prev_row = 0;
- this->cur_row = buf1;
+ this->cur_row = buf1.getPointer();
this->pos = 0;
memset(this->cur_row, 0, this->bytes_per_row + 1);