[Spice-devel] [PATCH qxl-win v3] display/res: make (Cursor|Palette)CacheRemove always release the object

Alon Levy alevy at redhat.com
Thu Jul 7 02:43:31 PDT 2011


From: Yonit Halperin <yhalperi at redhat.com>

even if it is not found in the cache (which is an error)
---
 display/res.c |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/display/res.c b/display/res.c
index 3f39c06..14b0c97 100644
--- a/display/res.c
+++ b/display/res.c
@@ -1547,6 +1547,7 @@ static _inline void ReleasePalette(PDev *pdev, InternalPalette *palette)
 static _inline void PaletteCacheRemove(PDev *pdev, InternalPalette *palette)
 {
     InternalPalette **internal;
+    BOOL found = FALSE;
 
     DEBUG_PRINT((pdev, 15, "%s\n", __FUNCTION__));
 
@@ -1556,15 +1557,22 @@ static _inline void PaletteCacheRemove(PDev *pdev, InternalPalette *palette)
     while (*internal) {
         if ((*internal)->palette.unique == palette->palette.unique) {
             *internal = palette->next;
-            RingRemove(pdev, &palette->lru_link);
-            ReleasePalette(pdev, palette);
-            pdev->Res->num_palettes--;
-            DEBUG_PRINT((pdev, 16, "%s: done\n", __FUNCTION__));
-            return;
+            found = TRUE;
+            break;
         }
         internal = &(*internal)->next;
     }
-    ASSERT(pdev, FALSE);
+
+    RingRemove(pdev, &palette->lru_link);
+    ReleasePalette(pdev, palette);
+    pdev->Res->num_palettes--;
+
+    if (!found) {
+        DEBUG_PRINT((pdev, 0, "%s: Error: palette 0x%x isn't in cache \n", __FUNCTION__, palette));
+        ASSERT(pdev, FALSE);
+    } else {
+        DEBUG_PRINT((pdev, 16, "%s: done\n", __FUNCTION__));
+    }
 }
 
 static _inline InternalPalette *PaletteCacheGet(PDev *pdev, UINT32 unique)
@@ -2872,29 +2880,36 @@ typedef struct InternalCursor {
 static void CursorCacheRemove(PDev *pdev, InternalCursor *cursor)
 {
     InternalCursor **internal;
+    BOOL found = FALSE;
 
     DEBUG_PRINT((pdev, 12, "%s\n", __FUNCTION__));
 
-    if (!cursor->unique) {
-        DEBUG_PRINT((pdev, 1, "%s: cursor not unique\n", __FUNCTION__));
-        return;
-    }
+    ASSERT(pdev, cursor->unique);
     internal = &pdev->Res->cursor_cache[CURSOR_HASH_VAL(cursor->hsurf)];
 
     while (*internal) {
         if ((*internal)->hsurf == cursor->hsurf) {
             if ((*internal) == cursor) {
                 *internal = cursor->next;
-                RingRemove(pdev, &cursor->lru_link);
-                RELEASE_RES(pdev, (Resource *)((UINT8 *)cursor - sizeof(Resource)));
-                pdev->Res->num_cursors--;
-                return;
+                found = TRUE;
+                break;
             }
             DEBUG_PRINT((pdev, 0, "%s: unexpected\n", __FUNCTION__));
         }
         internal = &(*internal)->next;
     }
-    DEBUG_PRINT((pdev, 0, "%s: Error: should not reach this\n", __FUNCTION__));
+
+    RingRemove(pdev, &cursor->lru_link);
+    RELEASE_RES(pdev, (Resource *)((UINT8 *)cursor - sizeof(Resource)));
+    pdev->Res->num_cursors--;
+
+    if (!found) {
+        DEBUG_PRINT((pdev, 0, "%s: Error: cursor 0x%x isn't in cache \n", __FUNCTION__, cursor));
+        ASSERT(pdev, FALSE);
+    } else {
+        DEBUG_PRINT((pdev, 16, "%s: done\n", __FUNCTION__));
+    }
+
 }
 
 static void CursorCacheAdd(PDev *pdev, InternalCursor *cursor)
-- 
1.7.5.4



More information about the Spice-devel mailing list