From f1ffe800324e9ff93dbf702b5c69fa72f8c90402 Mon Sep 17 00:00:00 2001
From: Ilyes Gouta <ilyes.gouta@st.com>
Date: Thu, 19 Jan 2012 11:35:47 +0100
Subject: [PATCH] surface_pool: mark an allocation as CSALF_DEALLOCATED on
 AllocateBuffer() failure

We don't need to go down till DeallocateBuffer() in dfb_surface_pool_deallocate() as AllocateBuffer() already failed allocating a valid chunk, thus
mark the allocation as CSALF_DEALLOCATED beforehand in dfb_surface_pool_allocate() on failure so that dfb_surface_pool_deallocate() bails out cleanly.

Also we don't clear allocation's MAGIC as surface_allocation_destructor() is expecting it to be still valid when calling dfb_surface_allocation_unref().
This latter will call dfb_surface_pool_deallocate() and then the system driver's (fbdev) DeallocateBuffer() which will fail in asserting a valid
D_MAGIC_ASSERT( local, FBDevPoolLocalData ) structure.
---
 src/core/surface_pool.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/core/surface_pool.c b/src/core/surface_pool.c
index 79dce80..b5476eb 100644
--- a/src/core/surface_pool.c
+++ b/src/core/surface_pool.c
@@ -731,7 +731,7 @@ dfb_surface_pool_allocate( CoreSurfacePool        *pool,
      ret = funcs->AllocateBuffer( pool, pool->data, get_local(pool), buffer, allocation, allocation->data );
      if (ret) {
           D_DEBUG_AT( Core_SurfacePool, "  -> %s\n", DirectFBErrorString( ret ) );
-          D_MAGIC_CLEAR( allocation );
+          allocation->flags |= CSALF_DEALLOCATED;
           fusion_skirmish_dismiss( &pool->lock );
           goto error;
      }
-- 
1.7.4.4

