2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

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.
This commit is contained in:
Jay Berkenbilt 2022-01-22 18:57:01 -05:00
parent d526d4c17f
commit b9cd693a5b
3 changed files with 4 additions and 8 deletions

View File

@ -26,7 +26,6 @@
#include <qpdf/Constants.h>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/QPDFArgParser.hh>
#include <memory>
#include <string>
@ -387,7 +386,6 @@ class QPDFJob
std::ostream* cout;
std::ostream* cerr;
unsigned long encryption_status;
std::shared_ptr<QPDFArgParser> ap;
};
std::shared_ptr<Members> m;
};

View File

@ -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<QPDFArgParser>(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();
}

View File

@ -1,6 +1,7 @@
#include <qpdf/QPDFJob.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh>
#include <qpdf/QPDFArgParser.hh>
#include <cstdio>
#include <cstdlib>