From 40f1946df8acb0bb7fefdc3ab31f6285bb11d032 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 6 Feb 2022 13:53:16 -0500 Subject: Replace PointerHolder arrays with shared_ptr arrays where possible Replace PointerHolder arrays wherever it can be done without breaking ABI. --- libqpdf/InputSource.cc | 4 ++-- libqpdf/Pl_DCT.cc | 3 +-- libqpdf/Pl_Flate.cc | 3 +-- libqpdf/QPDF_encryption.cc | 3 +-- libqpdf/QPDF_linearization.cc | 4 ++-- 5 files changed, 7 insertions(+), 10 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/InputSource.cc b/libqpdf/InputSource.cc index f9f63f17..3520ebf2 100644 --- a/libqpdf/InputSource.cc +++ b/libqpdf/InputSource.cc @@ -37,8 +37,8 @@ InputSource::readLine(size_t max_line_length) // point to position the file had when this method was called. qpdf_offset_t offset = this->tell(); - char* buf = new char[max_line_length + 1]; - PointerHolder bp(true, buf); + auto bp = std::make_unique(max_line_length + 1); + char* buf = bp.get(); memset(buf, '\0', max_line_length + 1); this->read(buf, max_line_length); this->seek(offset, SEEK_SET); diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index e4646dab..5b42b827 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -283,8 +283,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) # pragma GCC diagnostic pop #endif static int const BUF_SIZE = 65536; - PointerHolder outbuffer_ph( - true, new unsigned char[BUF_SIZE]); + auto outbuffer_ph = std::make_unique(BUF_SIZE); unsigned char* outbuffer = outbuffer_ph.get(); jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, this->getNext()); diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index a8b40867..586c3ea6 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -16,8 +16,7 @@ Pl_Flate::Members::Members(size_t out_bufsize, initialized(false), zdata(0) { - this->outbuf = PointerHolder( - true, new unsigned char[out_bufsize]); + this->outbuf = QUtil::make_shared_array(out_bufsize); // Indirect through zdata to reach the z_stream so we don't have // to include zlib.h in Pl_Flate.hh. This means people using // shared library versions of qpdf don't have to have zlib diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 5ce63e4c..83768414 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -204,8 +204,7 @@ iterate_rc4(unsigned char* data, size_t data_len, unsigned char* okey, int key_len, int iterations, bool reverse) { - PointerHolder key_ph = PointerHolder( - true, new unsigned char[QIntC::to_size(key_len)]); + auto key_ph = std::make_unique(QIntC::to_size(key_len)); unsigned char* key = key_ph.get(); for (int i = 0; i < iterations; ++i) { diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index c3c6f79e..49997423 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -97,9 +97,9 @@ QPDF::isLinearized() // Add a byte for a null terminator. static int const tbuf_size = 1025; - char* buf = new char[tbuf_size]; + auto b = std::make_unique(tbuf_size); + char* buf = b.get(); this->m->file->seek(0, SEEK_SET); - PointerHolder b(true, buf); memset(buf, '\0', tbuf_size); this->m->file->read(buf, tbuf_size - 1); -- cgit v1.2.3-70-g09d2