commit 0dff35a

Michael Forney  ·  2015-09-05 17:36:39 +0000 UTC
parent ce8e6e6
shm: Close buffer fds after mmap
1 files changed,  +9, -7
+9, -7
 1@@ -33,6 +33,7 @@
 2 #include <errno.h>
 3 #include <stdlib.h>
 4 #include <sys/mman.h>
 5+#include <unistd.h>
 6 #include <wayland-server.h>
 7 #include <wld/pixman.h>
 8 #include <wld/wld.h>
 9@@ -172,33 +173,34 @@ create_pool(struct wl_client *client, struct wl_resource *resource, uint32_t id,
10 
11 	if (!(pool = malloc(sizeof *pool))) {
12 		wl_resource_post_no_memory(resource);
13-		return;
14+		goto error0;
15 	}
16 
17 	pool->resource = wl_resource_create(client, &wl_shm_pool_interface, wl_resource_get_version(resource), id);
18 
19 	if (!pool->resource) {
20 		wl_resource_post_no_memory(resource);
21-		goto error0;
22+		goto error1;
23 	}
24 
25 	wl_resource_set_implementation(pool->resource, &shm_pool_implementation, pool, &destroy_pool_resource);
26 	pool->data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
27-
28 	if (pool->data == MAP_FAILED) {
29 		wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "mmap failed: %s", strerror(errno));
30-		goto error1;
31+		goto error2;
32 	}
33 
34+	close(fd);
35 	pool->size = size;
36 	pool->references = 1;
37-
38 	return;
39 
40-error1:
41+error2:
42 	wl_resource_destroy(pool->resource);
43-error0:
44+error1:
45 	free(pool);
46+error0:
47+	close(fd);
48 }
49 
50 static struct wl_shm_interface shm_implementation = {