PDF: Fail fast if in the tree of resources a child references a parent. Ideally I want a crash when the tree of resources became corrupt, not later when we try to finalize the pdf.
Review URL: https://codereview.appspot.com/6740047
git-svn-id: http://skia.googlecode.com/svn/trunk@6006 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index c1e2192..e148056 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -22,6 +22,15 @@
// resources).
device->getResources(&fResources, false);
+ // Fail fast if in the tree of resources a child references a parent.
+ // If there is an issue, getResources will end up consuming all memory.
+ // TODO: A better approach might be for all SkPDFObject to keep track
+ // of possible cycles.
+#ifdef SK_DEBUG
+ SkTDArray<SkPDFObject*> dummy_resourceList;
+ getResources(&dummy_resourceList);
+#endif
+
SkRefPtr<SkStream> content = device->content();
content->unref(); // SkRefPtr and content() both took a reference.
setData(content.get());