[cairo] [patch] subsurface: fix memory leak

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Thu Jun 14 13:33:35 PDT 2012


There is a memory leak in subsurface when _cairo_surface_subsurface_set_snapshot().  Test case subsurface-similar-repeat for GL backend
Here is the ref_count for surfaces for the test case in GL backend

1. after line 50, similar ref_count = 2; region ref_count = 1;
2. after line 51, similar ref_count = 1;
3. after line 76, similar ref_count = 1; region_ref_count = 2 - because GL sets region as the snapshot of similar, and thus increase ref_count for region
4. when cairo_restore(), region does not get destroyed because it has ref_count = 2.

My question is why we need to set a subsurface is a snapshot of its target?  Theoretically, it is correct.  But no backends call _cairo_surface_subsurface_set_snapshot() except GL and XCB backends.  in GL, we do need get snapshot of a subsurface.  So this call is needed, but I don't see why we need to set the subsurface as its target's snapshot.  No backends grab its snapshot when tries to extract the source pattern.  Better ideas on preserving subsurface as snapshot of its target and break cyclic referencing?

Thanks

Henry 

commit 103f987045bb636e44db86668655a8d4558faa69
Author: Henry Song <henry.song at samsung.com>
Date:   Thu Jun 14 13:14:04 2012 -0700

    subsurface:  There is a cyclic reference that causes memory when using
    _cairo_surface_subsurface_set_snapshot.  Why attach a subsurface as a
    snapshot to its target? - this is a cyclic reference.

diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index 90440c7..92a86d1 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -561,7 +561,4 @@ _cairo_surface_subsurface_set_snapshot (cairo_surface_t *surface,
 	_cairo_surface_detach_snapshot (ss->snapshot);
 
     ss->snapshot = cairo_surface_reference (snapshot);
-
-    _cairo_surface_attach_snapshot (ss->target, &ss->base,
-				    _cairo_surface_subsurface_detach_snapshot);
 }


More information about the cairo mailing list