PDF: Fix bug in weak pointer pattern.

For Canonicalized objects, only remove an object from the canonical list if it is the canonical object and not if it is an instance equal to the canonical object.

BUG=381
TBR=reed@google.com

Review URL: http://codereview.appspot.com/5330058

git-svn-id: http://skia.googlecode.com/svn/trunk@2559 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 5d358cb..e6a0f7f 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -703,7 +703,8 @@
 SkPDFFont::~SkPDFFont() {
     SkAutoMutexAcquire lock(CanonicalFontsMutex());
     int index;
-    if (Find(SkTypeface::UniqueID(fTypeface.get()), fFirstGlyphID, &index)) {
+    if (Find(SkTypeface::UniqueID(fTypeface.get()), fFirstGlyphID, &index) &&
+            CanonicalFonts()[index].fFont == this) {
         CanonicalFonts().removeShuffle(index);
     }
     fResources.unrefAll();
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index 3ac0e2f..d128630 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -54,6 +54,7 @@
     if (!fSMask) {
         int index = Find(fPaint);
         SkASSERT(index >= 0);
+        SkASSERT(CanonicalPaints()[index].fGraphicState == this);
         CanonicalPaints().removeShuffle(index);
     }
     fResources.unrefAll();