egl_dri2: Fix some valgrind reported leaks
authorBenjamin Franzke <benjaminfranzke@googlemail.com>
Tue, 13 Dec 2011 13:43:48 +0000 (14:43 +0100)
committerBenjamin Franzke <benjaminfranzke@googlemail.com>
Tue, 13 Dec 2011 14:32:43 +0000 (15:32 +0100)
Free the device_name, reported by Pekka Paalanen.

Destroy wayland display and drm resources,
if created by dri2_initialize_wayland.

src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_drm.c
src/egl/drivers/dri2/platform_wayland.c

index 44c9bc18d669754f4faa35995dfe140fa74e74e1..4c9ece351af2e6db7ce8253b6411ac16e928b14e 100644 (file)
@@ -608,6 +608,8 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
       close(dri2_dpy->fd);
    if (dri2_dpy->driver)
       dlclose(dri2_dpy->driver);
+   if (dri2_dpy->device_name)
+      free(dri2_dpy->device_name);
 
    if (disp->PlatformDisplay == NULL) {
       switch (disp->Platform) {
@@ -616,14 +618,9 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
          xcb_disconnect(dri2_dpy->conn);
          break;
 #endif
-#ifdef HAVE_WAYLAND_PLATFORM
-      case _EGL_PLATFORM_WAYLAND:
-         wl_display_destroy(dri2_dpy->wl_dpy);
-         break;
-#endif
 #ifdef HAVE_DRM_PLATFORM
       case _EGL_PLATFORM_DRM:
-         if (dri2_dpy->own_gbm_device) {
+         if (dri2_dpy->own_device) {
             gbm_device_destroy(&dri2_dpy->gbm_dri->base.base);
          }
          break;
index 95b87b875002bf93c4f59e084a74f71f72277982..193a866324fde7cac7be475c245a775c0e652b63 100644 (file)
@@ -101,9 +101,9 @@ struct dri2_egl_display
    __DRIimageExtension      *image;
    int                       fd;
 
+   int                       own_device;
 #ifdef HAVE_DRM_PLATFORM
    struct gbm_dri_device    *gbm_dri;
-   int                       own_gbm_device;
 #endif
 
    char                     *device_name;
index e2c8dab16bc869b86cd904a633e5afaf8e6ae352..3dc2c40c4e66cc229b17bdc247ce247fa80080dc 100644 (file)
@@ -108,7 +108,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    gbm = disp->PlatformDisplay;
    if (gbm == NULL) {
       fd = open("/dev/dri/card0", O_RDWR);
-      dri2_dpy->own_gbm_device = 1;
+      dri2_dpy->own_device = 1;
       gbm = gbm_create_device(fd);
       if (gbm == NULL)
          return EGL_FALSE;
index 7a70d8d59053a1b0c30a8e08b728fc222f9943b1..16c613f30d7ceb1831a3a84181f233f75935910d 100644 (file)
@@ -731,6 +731,10 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
    close(dri2_dpy->fd);
    dlclose(dri2_dpy->driver);
    free(dri2_dpy->driver_name);
+   free(dri2_dpy->device_name);
+   wl_drm_destroy(dri2_dpy->wl_drm);
+   if (dri2_dpy->own_device)
+      wl_display_destroy(dri2_dpy->wl_dpy);
    free(dri2_dpy);
    disp->DriverData = NULL;
 
@@ -819,6 +823,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
       dri2_dpy->wl_dpy = wl_display_connect(NULL);
       if (dri2_dpy->wl_dpy == NULL)
          goto cleanup_dpy;
+      dri2_dpy->own_device = 1;
    } else {
       dri2_dpy->wl_dpy = disp->PlatformDisplay;
    }