sw/xlib: NULL-out pointers after freeing image data
authorBrian Paul <brianp@vmware.com>
Mon, 24 May 2010 22:20:30 +0000 (16:20 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 24 May 2010 22:21:55 +0000 (16:21 -0600)
This fixes a double-free() error when not using a shared memory XImage.
The XDestroyImage() function frees the ximage->data buffer if non-NULL.
If we free it ourselves, we also need to NULL-out the pointer.

src/gallium/winsys/sw/xlib/xlib_sw_winsys.c

index 56d2df825dfbf1e94901dbf91be8bb94a5e10bab..3d702ae08dcdd719ad35068b3313d6ba4ba4141b 100644 (file)
@@ -255,11 +255,17 @@ xm_displaytarget_destroy(struct sw_winsys *ws,
       }
       else {
          FREE(xm_dt->data);
+         if (xm_dt->tempImage->data == xm_dt->data) {
+            xm_dt->tempImage->data = NULL;
+         }
+         xm_dt->data = NULL;
       }
    }
 
-   if (xm_dt->tempImage)
+   if (xm_dt->tempImage) {
       XDestroyImage(xm_dt->tempImage);
+      xm_dt->tempImage = NULL;
+   }
 
    if (xm_dt->gc)
       XFreeGC(xm_dt->display, xm_dt->gc);