screen-share: fix possible memory leak for `out_pixman_error` case

shm buffer should be freed in case of `out_pixman_error`, and should
be inserted into shared_output just before the success return.

Signed-off-by: xndcn <xndchn@gmail.com>
This commit is contained in:
xndcn 2021-01-05 22:47:04 +08:00
parent ed4a0e9275
commit ffe422116d
1 changed files with 3 additions and 1 deletions

View File

@ -485,7 +485,6 @@ shared_output_get_shm_buffer(struct shared_output *so)
sb->output = so;
wl_list_init(&sb->free_link);
wl_list_insert(&so->shm.buffers, &sb->link);
pixman_region32_init_rect(&sb->damage, 0, 0, width, height);
@ -510,10 +509,13 @@ shared_output_get_shm_buffer(struct shared_output *so)
if (!sb->pm_image)
goto out_pixman_error;
wl_list_insert(&so->shm.buffers, &sb->link);
return sb;
out_pixman_error:
wl_buffer_destroy(sb->buffer);
pixman_region32_fini(&sb->damage);
free(sb);
out_unmap:
munmap(data, height * stride);
out_close: