diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-02-06 19:53:16 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-02-07 23:38:22 +0100 |
commit | 40f1946df8acb0bb7fefdc3ab31f6285bb11d032 (patch) | |
tree | 87776a2a5f628bca1f4a1a0f46c4544aac7749e2 | |
parent | dd4f30226f3d4738e198dfcb944ce4cdc7e50a86 (diff) | |
download | qpdf-40f1946df8acb0bb7fefdc3ab31f6285bb11d032.tar.zst |
Replace PointerHolder arrays with shared_ptr arrays where possible
Replace PointerHolder arrays wherever it can be done without breaking ABI.
-rw-r--r-- | include/qpdf/Pl_Flate.hh | 3 | ||||
-rw-r--r-- | libqpdf/InputSource.cc | 4 | ||||
-rw-r--r-- | libqpdf/Pl_DCT.cc | 3 | ||||
-rw-r--r-- | libqpdf/Pl_Flate.cc | 3 | ||||
-rw-r--r-- | libqpdf/QPDF_encryption.cc | 3 | ||||
-rw-r--r-- | libqpdf/QPDF_linearization.cc | 4 |
6 files changed, 9 insertions, 11 deletions
diff --git a/include/qpdf/Pl_Flate.hh b/include/qpdf/Pl_Flate.hh index 5e63f1ac..cec76ca7 100644 --- a/include/qpdf/Pl_Flate.hh +++ b/include/qpdf/Pl_Flate.hh @@ -24,6 +24,7 @@ #include <qpdf/Pipeline.hh> #include <functional> +#include <memory> class Pl_Flate: public Pipeline { @@ -73,7 +74,7 @@ class Pl_Flate: public Pipeline Members(size_t out_bufsize, action_e action); Members(Members const&); - PointerHolder<unsigned char> outbuf; + std::shared_ptr<unsigned char> outbuf; size_t out_bufsize; action_e action; bool initialized; 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<char> bp(true, buf); + auto bp = std::make_unique<char[]>(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<unsigned char> outbuffer_ph( - true, new unsigned char[BUF_SIZE]); + auto outbuffer_ph = std::make_unique<unsigned char[]>(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<unsigned char>( - true, new unsigned char[out_bufsize]); + this->outbuf = QUtil::make_shared_array<unsigned char>(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<unsigned char> key_ph = PointerHolder<unsigned char>( - true, new unsigned char[QIntC::to_size(key_len)]); + auto key_ph = std::make_unique<unsigned char[]>(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<char[]>(tbuf_size); + char* buf = b.get(); this->m->file->seek(0, SEEK_SET); - PointerHolder<char> b(true, buf); memset(buf, '\0', tbuf_size); this->m->file->read(buf, tbuf_size - 1); |