[Cogl] [PATCH] matrix-stack: getting parent ptr before freeing

Robert Bragg robert at sixbynine.org
Wed Nov 28 12:48:59 PST 2012


From: Robert Bragg <robert at linux.intel.com>

When unrefing a CoglMatrixEntry we walk up the ancestry unrefing and
freeing entries until we find an entry that doesn't need to be freed.
The problem fixed by this patch was that we didn't dereference the
parent member of each entry until after the entry was freed and so there
was the potential for reading a junk parent pointer back.
---
 cogl/cogl-matrix-stack.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/cogl/cogl-matrix-stack.c b/cogl/cogl-matrix-stack.c
index e5ad10d..4d5b9eb 100644
--- a/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl-matrix-stack.c
@@ -328,8 +328,12 @@ _cogl_matrix_entry_ref (CoglMatrixEntry *entry)
 void
 _cogl_matrix_entry_unref (CoglMatrixEntry *entry)
 {
-  for (; entry && --entry->ref_count <= 0; entry = entry->parent)
+  CoglMatrixEntry *parent;
+
+  for (; entry && --entry->ref_count <= 0; entry = parent)
     {
+      parent = entry->parent;
+
       switch (entry->op)
         {
         case COGL_MATRIX_OP_LOAD_IDENTITY:
-- 
1.7.7.6



More information about the Cogl mailing list