diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-09-08 14:03:57 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-09-08 16:36:39 +0200 |
commit | dba61da1bfb7e4d74c723f369d1c017df9707a14 (patch) | |
tree | 04c51f86dc066c710c23423fe178e051b20b49d9 /libqpdf/QPDF.cc | |
parent | 264e25f391f83bcbeb60590f18ff96719b086454 (diff) | |
download | qpdf-dba61da1bfb7e4d74c723f369d1c017df9707a14.tar.zst |
Create a special "destroyed" type rather than using null
When a QPDF is destroyed, changing indirect objects to direct nulls
makes them effectively disappear silently when they sneak into other
places. Instead, we should treat this as an error. Adding a destroyed
object type makes this possible.
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r-- | libqpdf/QPDF.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 40390055..c66cfd5a 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -249,22 +249,23 @@ QPDF::~QPDF() // std::shared_ptr objects will prevent the objects from being // deleted. Walk through all objects in the object cache, which is // those objects that we read from the file, and break all - // resolved indirect references by replacing them with direct null - // objects. At this point, obviously no one is still using the - // QPDF object, but we'll explicitly clear the xref table anyway - // just to prevent any possibility of resolve() succeeding. Note + // resolved indirect references by replacing them with an internal + // object type representing that they have been destroyed. Note // that we can't break references like this at any time when the - // QPDF object is active. This also causes all QPDFObjectHandle - // objects that are reachable from this object to become nulls and + // QPDF object is active. The call to reset also causes all + // QPDFObjectHandle objects that are reachable from this object to // release their association with this QPDF. + + // At this point, obviously no one is still using the QPDF object, + // but we'll explicitly clear the xref table anyway just to + // prevent any possibility of resolve() succeeding. this->m->xref_table.clear(); auto null_obj = QPDF_Null::create(); for (auto const& iter: this->m->obj_cache) { iter.second.object->reset(); - // If the issue discussed in QPDFValueProxy::reset were - // resolved, then this assignment to null_obj could be - // removed. - iter.second.object->assign(null_obj); + // It would be better if reset() could call destroy(), but it + // can't -- see comments in QPDFValueProxy::reset(). + iter.second.object->destroy(); } } |