Fix read from pointer after free
authorAnuj Phogat <anuj.phogat@gmail.com>
Wed, 4 Jan 2012 02:12:06 +0000 (18:12 -0800)
committerAnuj Phogat <anuj.phogat@gmail.com>
Wed, 4 Jan 2012 03:04:03 +0000 (19:04 -0800)
Coverity reported a read from pointer after free defect in
src/mesa/drivers/dri/intel/intel_mipmap_tree.c. Bug# 44205
In intel_miptree_all_slices_resolve() function, i = i->next was
executing after freeing i. I have defined a temporary variable
(next) to store the value of i->next before freeing i

Reported-by: Vinson Lee <vlee@vmware.com>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/intel/intel_mipmap_tree.c

index 60cc694ee0cd917ad7c8c4887a84e22ae17ca7c8..7787c1a87af0c880943f37c6927eca3fec2014a8 100644 (file)
@@ -640,12 +640,13 @@ intel_miptree_all_slices_resolve(struct intel_context *intel,
                                 resolve_func_t func)
 {
    bool did_resolve = false;
-   struct intel_resolve_map *i;
+   struct intel_resolve_map *i, *next;
 
-   for (i = mt->hiz_map.next; i; i = i->next) {
+   for (i = mt->hiz_map.next; i; i = next) {
       if (i->need != need)
         continue;
       func(intel, mt, i->level, i->layer);
+      next = i->next;
       intel_resolve_map_remove(i);
       did_resolve = true;
    }