window: Only unmap shm surface backing memory if it belongs to surface
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 10 Apr 2012 15:32:35 +0000 (11:32 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 10 Apr 2012 15:32:35 +0000 (11:32 -0400)
Memory allocated out of the resize shm pool will be unmapped when the pool
is destroyed.

clients/window.c

index 9be6764..8a682b4 100644 (file)
@@ -464,7 +464,8 @@ shm_surface_data_destroy(void *p)
        struct shm_surface_data *data = p;
 
        wl_buffer_destroy(data->data.buffer);
-       munmap(data->map, data->length);
+       if (data->map)
+               munmap(data->map, data->length);
 }
 
 static struct wl_shm_pool *
@@ -523,9 +524,10 @@ display_create_shm_surface(struct display *display,
        if (window && window->pool && data->length < window->pool_size) {
                pool = window->pool;
                map = window->pool_data;
+               data->map = NULL;
        } else {
-               pool = make_shm_pool(display, data->length, &data->map);
-               map = data->map;
+               pool = make_shm_pool(display, data->length, &map);
+               data->map = map;
        }
 
        surface = cairo_image_surface_create_for_data (map,
@@ -547,7 +549,7 @@ display_create_shm_surface(struct display *display,
                                                      rectangle->height,
                                                      stride, format);
 
-       if (map == data->map)
+       if (data->map)
                wl_shm_pool_destroy(pool);
 
        return surface;