2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 10:50:53 +00:00

Reset QPDFValue::qpdf and QPDFValue::og when the owning QPDF object gets destroyed

This commit is contained in:
m-holger 2022-08-15 15:13:11 +01:00
parent 2b7e9ba2f5
commit 805c1ad479
3 changed files with 23 additions and 3 deletions

View File

@ -259,6 +259,7 @@ QPDF::~QPDF()
this->m->xref_table.clear();
for (auto const& iter: this->m->obj_cache) {
QPDFObject::ObjAccessor::releaseResolved(iter.second.object.get());
iter.second.object->resetObjGen();
}
}

View File

@ -14,7 +14,7 @@ cleanup();
my $td = new TestDriver('type-checks');
my $n_tests = 5;
my $n_tests = 6;
# Whenever object-types.pdf is edited, object-types-os.pdf should be
# regenerated.
@ -43,6 +43,10 @@ $td->runtest("compound type checks",
{$td->COMMAND => "test_driver 82 object-types-os.pdf"},
{$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("indirect objects belonging to destroyed QPDF",
{$td->COMMAND => "test_driver 92 -"},
{$td->STRING => "test 92 done\n", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);

View File

@ -3258,6 +3258,20 @@ test_91(QPDF& pdf, char const* arg2)
2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>());
}
static void
test_92(QPDF& pdf, char const* arg2)
{
// Exercise indirect objects owned by destroyed QPDF object.
QPDF* qpdf = new QPDF();
qpdf->emptyPDF();
auto root = qpdf->getRoot();
assert(root.getOwningQPDF() != nullptr);
assert(root.isIndirect());
delete qpdf;
assert(root.getOwningQPDF() == nullptr);
assert(!root.isIndirect());
}
void
runtest(int n, char const* filename1, char const* arg2)
{
@ -3265,7 +3279,7 @@ runtest(int n, char const* filename1, char const* arg2)
// the test suite to see how the test is invoked to find the file
// that the test is supposed to operate on.
std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87};
std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92};
if (n == 0) {
// Throw in some random test cases that don't fit anywhere
@ -3362,7 +3376,8 @@ runtest(int n, char const* filename1, char const* arg2)
{76, test_76}, {77, test_77}, {78, test_78}, {79, test_79},
{80, test_80}, {81, test_81}, {82, test_82}, {83, test_83},
{84, test_84}, {85, test_85}, {86, test_86}, {87, test_87},
{88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}};
{88, test_88}, {89, test_89}, {90, test_90}, {91, test_91},
{92, test_92}};
auto fn = test_functions.find(n);
if (fn == test_functions.end()) {