mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-04 13:29:51 -05:00
shm: Plug leak in shm_create_pool()
This commit is contained in:
parent
53bb401704
commit
c94c0946db
1 changed files with 9 additions and 6 deletions
|
|
@ -188,29 +188,27 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
||||||
pool = malloc(sizeof *pool);
|
pool = malloc(sizeof *pool);
|
||||||
if (pool == NULL) {
|
if (pool == NULL) {
|
||||||
wl_resource_post_no_memory(resource);
|
wl_resource_post_no_memory(resource);
|
||||||
close(fd);
|
goto err_close;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
wl_resource_post_error(resource,
|
wl_resource_post_error(resource,
|
||||||
WL_SHM_ERROR_INVALID_STRIDE,
|
WL_SHM_ERROR_INVALID_STRIDE,
|
||||||
"invalid size (%d)", size);
|
"invalid size (%d)", size);
|
||||||
close(fd);
|
goto err_free;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pool->refcount = 1;
|
pool->refcount = 1;
|
||||||
pool->size = size;
|
pool->size = size;
|
||||||
pool->data = mmap(NULL, size,
|
pool->data = mmap(NULL, size,
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
close(fd);
|
|
||||||
if (pool->data == MAP_FAILED) {
|
if (pool->data == MAP_FAILED) {
|
||||||
wl_resource_post_error(resource,
|
wl_resource_post_error(resource,
|
||||||
WL_SHM_ERROR_INVALID_FD,
|
WL_SHM_ERROR_INVALID_FD,
|
||||||
"failed mmap fd %d", fd);
|
"failed mmap fd %d", fd);
|
||||||
return;
|
goto err_free;
|
||||||
}
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
pool->resource.object.id = id;
|
pool->resource.object.id = id;
|
||||||
pool->resource.object.interface = &wl_shm_pool_interface;
|
pool->resource.object.interface = &wl_shm_pool_interface;
|
||||||
|
|
@ -222,6 +220,11 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
||||||
pool->resource.destroy = destroy_pool;
|
pool->resource.destroy = destroy_pool;
|
||||||
|
|
||||||
wl_client_add_resource(client, &pool->resource);
|
wl_client_add_resource(client, &pool->resource);
|
||||||
|
|
||||||
|
err_close:
|
||||||
|
close(fd);
|
||||||
|
err_free:
|
||||||
|
free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_shm_interface shm_interface = {
|
static const struct wl_shm_interface shm_interface = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue