diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index 199584fe..52f02a0d 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -105,22 +106,25 @@ void ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline) { - std::vector > to_delete; + std::vector> to_delete; Pipeline* p = pipeline; + std::shared_ptr p_new; if (filter == "/DCTDecode") { - p = new Pl_DCT( + p_new = std::make_shared( "image encoder", pipeline, QIntC::to_uint(width), QIntC::to_uint(getHeight()), QIntC::to_int(stripes[0].length()), j_color_space); - to_delete.push_back(p); + to_delete.push_back(p_new); + p = p_new.get(); } else if (filter == "/RunLengthDecode") { - p = new Pl_RunLength( + p_new = std::make_shared( "image encoder", pipeline, Pl_RunLength::a_encode); - to_delete.push_back(p); + to_delete.push_back(p_new); + p = p_new.get(); } for (size_t i = 0; i < n_stripes; ++i) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index a2820e4a..ac395358 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -1024,7 +1024,7 @@ class QPDF QPDF& qpdf_for_warning, Pipeline*& pipeline, int objid, int generation, QPDFObjectHandle& stream_dict, - std::vector >& heap); + std::vector>& heap); // Methods to support object copying void reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, diff --git a/include/qpdf/QPDFWriter.hh b/include/qpdf/QPDFWriter.hh index 8044d054..b434b033 100644 --- a/include/qpdf/QPDFWriter.hh +++ b/include/qpdf/QPDFWriter.hh @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -684,7 +685,7 @@ class QPDFWriter std::string extra_header_text; int encryption_dict_objid; std::string cur_data_key; - std::list > to_delete; + std::list> to_delete; Pl_Count* pipeline; std::list object_queue; std::map obj_renumber; diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 36c812b2..120feee8 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -2910,7 +2910,7 @@ QPDF::pipeStreamData(PointerHolder encp, bool suppress_warnings, bool will_retry) { - std::vector > to_delete; + std::vector> to_delete; if (encp->encrypted) { decryptStream(encp, file, qpdf_for_warning, diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index ede35d7e..f426f151 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -132,9 +132,10 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) this->m->filename = description; this->m->file = file; this->m->close_file = close_file; - Pipeline* p = new Pl_StdioFile("qpdf output", file); + std::shared_ptr p = std::make_shared( + "qpdf output", file); this->m->to_delete.push_back(p); - initializePipelineStack(p); + initializePipelineStack(p.get()); } void @@ -142,7 +143,8 @@ QPDFWriter::setOutputMemory() { this->m->filename = "memory buffer"; this->m->buffer_pipeline = new Pl_Buffer("qpdf output"); - this->m->to_delete.push_back(this->m->buffer_pipeline); + this->m->to_delete.push_back( + std::shared_ptr(this->m->buffer_pipeline)); initializePipelineStack(this->m->buffer_pipeline); } @@ -1051,7 +1053,8 @@ void QPDFWriter::initializePipelineStack(Pipeline *p) { this->m->pipeline = new Pl_Count("pipeline stack base", p); - this->m->to_delete.push_back(this->m->pipeline); + this->m->to_delete.push_back( + std::shared_ptr(this->m->pipeline)); this->m->pipeline_stack.push_back(this->m->pipeline); } diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index 8137e211..d905d491 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -463,34 +463,36 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool* filterp, // create to be deleted when this function finishes. Pipelines // created by QPDFStreamFilter objects will be deleted by those // objects. - std::vector> to_delete; + std::vector> to_delete; PointerHolder normalizer; + std::shared_ptr new_pipeline; if (filter) { if (encode_flags & qpdf_ef_compress) { - pipeline = new Pl_Flate("compress stream", pipeline, - Pl_Flate::a_deflate); - to_delete.push_back(pipeline); + new_pipeline = std::make_shared( + "compress stream", pipeline, Pl_Flate::a_deflate); + to_delete.push_back(new_pipeline); + pipeline = new_pipeline.get(); } if (encode_flags & qpdf_ef_normalize) { normalizer = new ContentNormalizer(); - pipeline = new Pl_QPDFTokenizer( + new_pipeline = std::make_shared( "normalizer", normalizer.get(), pipeline); - to_delete.push_back(pipeline); + to_delete.push_back(new_pipeline); + pipeline = new_pipeline.get(); } - for (std::vector >::reverse_iterator iter = - this->token_filters.rbegin(); + for (auto iter = this->token_filters.rbegin(); iter != this->token_filters.rend(); ++iter) { - pipeline = new Pl_QPDFTokenizer( + new_pipeline = std::make_shared( "token filter", (*iter).get(), pipeline); - to_delete.push_back(pipeline); + to_delete.push_back(new_pipeline); + pipeline = new_pipeline.get(); } for (auto f_iter = filters.rbegin(); diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index fff35c67..54c2dadc 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -1238,7 +1238,7 @@ QPDF::decryptStream(PointerHolder encp, QPDF& qpdf_for_warning, Pipeline*& pipeline, int objid, int generation, QPDFObjectHandle& stream_dict, - std::vector >& heap) + std::vector>& heap) { std::string type; if (stream_dict.getKey("/Type").isName()) @@ -1343,21 +1343,25 @@ QPDF::decryptStream(PointerHolder encp, } } std::string key = getKeyForObject(encp, objid, generation, use_aes); + std::shared_ptr new_pipeline; if (use_aes) { QTC::TC("qpdf", "QPDF_encryption aes decode stream"); - pipeline = new Pl_AES_PDF("AES stream decryption", pipeline, - false, QUtil::unsigned_char_pointer(key), - key.length()); + new_pipeline = std::make_shared( + "AES stream decryption", pipeline, + false, QUtil::unsigned_char_pointer(key), + key.length()); } else { QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); - pipeline = new Pl_RC4("RC4 stream decryption", pipeline, - QUtil::unsigned_char_pointer(key), - toI(key.length())); + new_pipeline = std::make_shared( + "RC4 stream decryption", pipeline, + QUtil::unsigned_char_pointer(key), + toI(key.length())); } - heap.push_back(pipeline); + pipeline = new_pipeline.get(); + heap.push_back(new_pipeline); } void