Commit 40f1946df8acb0bb7fefdc3ab31f6285bb11d032
1 parent
dd4f3022
Replace PointerHolder arrays with shared_ptr arrays where possible
Replace PointerHolder arrays wherever it can be done without breaking ABI.
Showing
6 changed files
with
9 additions
and
11 deletions
include/qpdf/Pl_Flate.hh
| ... | ... | @@ -24,6 +24,7 @@ |
| 24 | 24 | |
| 25 | 25 | #include <qpdf/Pipeline.hh> |
| 26 | 26 | #include <functional> |
| 27 | +#include <memory> | |
| 27 | 28 | |
| 28 | 29 | class Pl_Flate: public Pipeline |
| 29 | 30 | { |
| ... | ... | @@ -73,7 +74,7 @@ class Pl_Flate: public Pipeline |
| 73 | 74 | Members(size_t out_bufsize, action_e action); |
| 74 | 75 | Members(Members const&); |
| 75 | 76 | |
| 76 | - PointerHolder<unsigned char> outbuf; | |
| 77 | + std::shared_ptr<unsigned char> outbuf; | |
| 77 | 78 | size_t out_bufsize; |
| 78 | 79 | action_e action; |
| 79 | 80 | bool initialized; | ... | ... |
libqpdf/InputSource.cc
| ... | ... | @@ -37,8 +37,8 @@ InputSource::readLine(size_t max_line_length) |
| 37 | 37 | // point to position the file had when this method was called. |
| 38 | 38 | |
| 39 | 39 | qpdf_offset_t offset = this->tell(); |
| 40 | - char* buf = new char[max_line_length + 1]; | |
| 41 | - PointerHolder<char> bp(true, buf); | |
| 40 | + auto bp = std::make_unique<char[]>(max_line_length + 1); | |
| 41 | + char* buf = bp.get(); | |
| 42 | 42 | memset(buf, '\0', max_line_length + 1); |
| 43 | 43 | this->read(buf, max_line_length); |
| 44 | 44 | this->seek(offset, SEEK_SET); | ... | ... |
libqpdf/Pl_DCT.cc
| ... | ... | @@ -283,8 +283,7 @@ Pl_DCT::compress(void* cinfo_p, Buffer* b) |
| 283 | 283 | # pragma GCC diagnostic pop |
| 284 | 284 | #endif |
| 285 | 285 | static int const BUF_SIZE = 65536; |
| 286 | - PointerHolder<unsigned char> outbuffer_ph( | |
| 287 | - true, new unsigned char[BUF_SIZE]); | |
| 286 | + auto outbuffer_ph = std::make_unique<unsigned char[]>(BUF_SIZE); | |
| 288 | 287 | unsigned char* outbuffer = outbuffer_ph.get(); |
| 289 | 288 | jpeg_pipeline_dest(cinfo, outbuffer, BUF_SIZE, this->getNext()); |
| 290 | 289 | ... | ... |
libqpdf/Pl_Flate.cc
| ... | ... | @@ -16,8 +16,7 @@ Pl_Flate::Members::Members(size_t out_bufsize, |
| 16 | 16 | initialized(false), |
| 17 | 17 | zdata(0) |
| 18 | 18 | { |
| 19 | - this->outbuf = PointerHolder<unsigned char>( | |
| 20 | - true, new unsigned char[out_bufsize]); | |
| 19 | + this->outbuf = QUtil::make_shared_array<unsigned char>(out_bufsize); | |
| 21 | 20 | // Indirect through zdata to reach the z_stream so we don't have |
| 22 | 21 | // to include zlib.h in Pl_Flate.hh. This means people using |
| 23 | 22 | // shared library versions of qpdf don't have to have zlib | ... | ... |
libqpdf/QPDF_encryption.cc
| ... | ... | @@ -204,8 +204,7 @@ iterate_rc4(unsigned char* data, size_t data_len, |
| 204 | 204 | unsigned char* okey, int key_len, |
| 205 | 205 | int iterations, bool reverse) |
| 206 | 206 | { |
| 207 | - PointerHolder<unsigned char> key_ph = PointerHolder<unsigned char>( | |
| 208 | - true, new unsigned char[QIntC::to_size(key_len)]); | |
| 207 | + auto key_ph = std::make_unique<unsigned char[]>(QIntC::to_size(key_len)); | |
| 209 | 208 | unsigned char* key = key_ph.get(); |
| 210 | 209 | for (int i = 0; i < iterations; ++i) |
| 211 | 210 | { | ... | ... |
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -97,9 +97,9 @@ QPDF::isLinearized() |
| 97 | 97 | // Add a byte for a null terminator. |
| 98 | 98 | static int const tbuf_size = 1025; |
| 99 | 99 | |
| 100 | - char* buf = new char[tbuf_size]; | |
| 100 | + auto b = std::make_unique<char[]>(tbuf_size); | |
| 101 | + char* buf = b.get(); | |
| 101 | 102 | this->m->file->seek(0, SEEK_SET); |
| 102 | - PointerHolder<char> b(true, buf); | |
| 103 | 103 | memset(buf, '\0', tbuf_size); |
| 104 | 104 | this->m->file->read(buf, tbuf_size - 1); |
| 105 | 105 | ... | ... |