If the stack is too deep we could get Stack Overflow in pdf's ContentEntry's destructor.
Review URL: https://codereview.appspot.com/7313045

git-svn-id: http://skia.googlecode.com/svn/trunk@7605 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index e253a5f..00411a1 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -495,6 +495,22 @@
     GraphicStateEntry fState;
     SkDynamicMemoryWStream fContent;
     SkTScopedPtr<ContentEntry> fNext;
+
+    // If the stack is too deep we could get Stack Overflow.
+    // So we manually destruct the object.
+    ~ContentEntry() {
+        ContentEntry* val = fNext.release();
+        if (NULL == val) {
+            return;
+        }
+
+        while (val != NULL) {
+            ContentEntry* valNext = val->fNext.release();
+            // When the destructor is called, fNext is NULL and exits.
+            delete val;
+            val = valNext;
+        }
+    }
 };
 
 // A helper class to automatically finish a ContentEntry at the end of a