From b9cd693a5b36b8b0246822cb97386792045179ec Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jan 2022 18:57:01 -0500 Subject: [PATCH] QPDFJob: allocate QPDFArgParser on stack The previous commits have removed all references to memory from QPDFArgParser from QPDFJob. This commit removes the constraint that QPDFArgParser remain in scope. This is a prerequisite to allowing JSON as an alternative way to initialize QPDFJob and to initialize it directly using a public API. --- include/qpdf/QPDFJob.hh | 2 -- libqpdf/QPDFJob_argv.cc | 9 +++------ qpdf/qpdf.cc | 1 + 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 4192be66..de51dc57 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -387,7 +386,6 @@ class QPDFJob std::ostream* cout; std::ostream* cerr; unsigned long encryption_status; - std::shared_ptr ap; }; std::shared_ptr m; }; diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index 316beda0..8da5e836 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -1529,11 +1529,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) { progname_env = "QPDF_EXECUTABLE"; } - // QPDFArgParser must stay in scope for the life of the QPDFJob - // object since it holds dynamic memory used for argv, which is - // pointed to by other member variables. - this->m->ap = std::make_shared(argc, argv, progname_env); - setMessagePrefix(this->m->ap->getProgname()); - ArgParser ap(*this->m->ap, *this); + QPDFArgParser qap(argc, argv, progname_env); + setMessagePrefix(qap.getProgname()); + ArgParser ap(qap, *this); ap.parseOptions(); } diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 77fb8cb1..04cd2244 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include