Commit 805c1ad47968e33e1296af9a31492f6916ad9113
1 parent
2b7e9ba2
Reset QPDFValue::qpdf and QPDFValue::og when the owning QPDF object gets destroyed
Showing
3 changed files
with
23 additions
and
3 deletions
libqpdf/QPDF.cc
| @@ -259,6 +259,7 @@ QPDF::~QPDF() | @@ -259,6 +259,7 @@ QPDF::~QPDF() | ||
| 259 | this->m->xref_table.clear(); | 259 | this->m->xref_table.clear(); |
| 260 | for (auto const& iter: this->m->obj_cache) { | 260 | for (auto const& iter: this->m->obj_cache) { |
| 261 | QPDFObject::ObjAccessor::releaseResolved(iter.second.object.get()); | 261 | QPDFObject::ObjAccessor::releaseResolved(iter.second.object.get()); |
| 262 | + iter.second.object->resetObjGen(); | ||
| 262 | } | 263 | } |
| 263 | } | 264 | } |
| 264 | 265 |
qpdf/qtest/type-checks.test
| @@ -14,7 +14,7 @@ cleanup(); | @@ -14,7 +14,7 @@ cleanup(); | ||
| 14 | 14 | ||
| 15 | my $td = new TestDriver('type-checks'); | 15 | my $td = new TestDriver('type-checks'); |
| 16 | 16 | ||
| 17 | -my $n_tests = 5; | 17 | +my $n_tests = 6; |
| 18 | 18 | ||
| 19 | # Whenever object-types.pdf is edited, object-types-os.pdf should be | 19 | # Whenever object-types.pdf is edited, object-types-os.pdf should be |
| 20 | # regenerated. | 20 | # regenerated. |
| @@ -43,6 +43,10 @@ $td->runtest("compound type checks", | @@ -43,6 +43,10 @@ $td->runtest("compound type checks", | ||
| 43 | {$td->COMMAND => "test_driver 82 object-types-os.pdf"}, | 43 | {$td->COMMAND => "test_driver 82 object-types-os.pdf"}, |
| 44 | {$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0}, | 44 | {$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0}, |
| 45 | $td->NORMALIZE_NEWLINES); | 45 | $td->NORMALIZE_NEWLINES); |
| 46 | +$td->runtest("indirect objects belonging to destroyed QPDF", | ||
| 47 | + {$td->COMMAND => "test_driver 92 -"}, | ||
| 48 | + {$td->STRING => "test 92 done\n", $td->EXIT_STATUS => 0}, | ||
| 49 | + $td->NORMALIZE_NEWLINES); | ||
| 46 | 50 | ||
| 47 | cleanup(); | 51 | cleanup(); |
| 48 | $td->report($n_tests); | 52 | $td->report($n_tests); |
qpdf/test_driver.cc
| @@ -3258,6 +3258,20 @@ test_91(QPDF& pdf, char const* arg2) | @@ -3258,6 +3258,20 @@ test_91(QPDF& pdf, char const* arg2) | ||
| 3258 | 2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>()); | 3258 | 2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>()); |
| 3259 | } | 3259 | } |
| 3260 | 3260 | ||
| 3261 | +static void | ||
| 3262 | +test_92(QPDF& pdf, char const* arg2) | ||
| 3263 | +{ | ||
| 3264 | + // Exercise indirect objects owned by destroyed QPDF object. | ||
| 3265 | + QPDF* qpdf = new QPDF(); | ||
| 3266 | + qpdf->emptyPDF(); | ||
| 3267 | + auto root = qpdf->getRoot(); | ||
| 3268 | + assert(root.getOwningQPDF() != nullptr); | ||
| 3269 | + assert(root.isIndirect()); | ||
| 3270 | + delete qpdf; | ||
| 3271 | + assert(root.getOwningQPDF() == nullptr); | ||
| 3272 | + assert(!root.isIndirect()); | ||
| 3273 | +} | ||
| 3274 | + | ||
| 3261 | void | 3275 | void |
| 3262 | runtest(int n, char const* filename1, char const* arg2) | 3276 | runtest(int n, char const* filename1, char const* arg2) |
| 3263 | { | 3277 | { |
| @@ -3265,7 +3279,7 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3265,7 +3279,7 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3265 | // the test suite to see how the test is invoked to find the file | 3279 | // the test suite to see how the test is invoked to find the file |
| 3266 | // that the test is supposed to operate on. | 3280 | // that the test is supposed to operate on. |
| 3267 | 3281 | ||
| 3268 | - std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87}; | 3282 | + std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92}; |
| 3269 | 3283 | ||
| 3270 | if (n == 0) { | 3284 | if (n == 0) { |
| 3271 | // Throw in some random test cases that don't fit anywhere | 3285 | // Throw in some random test cases that don't fit anywhere |
| @@ -3362,7 +3376,8 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3362,7 +3376,8 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3362 | {76, test_76}, {77, test_77}, {78, test_78}, {79, test_79}, | 3376 | {76, test_76}, {77, test_77}, {78, test_78}, {79, test_79}, |
| 3363 | {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, | 3377 | {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, |
| 3364 | {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, | 3378 | {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, |
| 3365 | - {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}}; | 3379 | + {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}, |
| 3380 | + {92, test_92}}; | ||
| 3366 | 3381 | ||
| 3367 | auto fn = test_functions.find(n); | 3382 | auto fn = test_functions.find(n); |
| 3368 | if (fn == test_functions.end()) { | 3383 | if (fn == test_functions.end()) { |