Fix memory leak when reconstructing broken files
Need to free the catalog variable if we're going to fetch over it again
Bug #100776
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index c141bbf..6ea0fbb 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1144,13 +1144,16 @@
}
Object *XRef::getCatalog(Object *catalog) {
- Object *obj = fetch(rootNum, rootGen, catalog);
- if (obj->isDict()) {
- return obj;
+ fetch(rootNum, rootGen, catalog);
+ if (catalog->isDict()) {
+ return catalog;
}
GBool wasReconstructed = false;
- GBool ok = constructXRef(&wasReconstructed, gTrue);
- return (ok) ? fetch(rootNum, rootGen, catalog) : obj;
+ if (constructXRef(&wasReconstructed, gTrue)) {
+ catalog->free();
+ fetch(rootNum, rootGen, catalog);
+ }
+ return catalog;
}
Object *XRef::fetch(int num, int gen, Object *obj, int recursion) {