tests: fix leak in surface_commit_color() in pointer-shot

Found by ASan, several leaks like:

Direct leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7f35fdc9c518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x55a77d6a4c6a in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x55a77d6a748e in create_shm_buffer ../../git/weston/tests/weston-test-client-helper.c:459
    #3 0x55a77d6a78cd in create_shm_buffer_a8r8g8b8 ../../git/weston/tests/weston-test-client-helper.c:499
    #4 0x55a77d6a4145 in surface_commit_color ../../git/weston/tests/pointer-shot-test.c:89
    #5 0x55a77d6a4542 in pointer_cursor_retains_committed_buffer_after_reenter ../../git/weston/tests/pointer-shot-test.c:135
    #6 0x55a77d6a4207 in wrappointer_cursor_retains_committed_buffer_after_reenter ../../git/weston/tests/pointer-shot-test.c:98
    #7 0x55a77d6b15c2 in run_test ../../git/weston/tests/weston-test-runner.c:162
    #8 0x55a77d6b1c63 in run_case ../../git/weston/tests/weston-test-runner.c:277
    #9 0x55a77d6b1a09 in for_each_test_case ../../git/weston/tests/weston-test-runner.c:235
    #10 0x55a77d6b1eeb in testsuite_run ../../git/weston/tests/weston-test-runner.c:311
    #11 0x7f35f9510b6b in client_thread_routine ../../git/weston/tests/weston-test.c:479
    #12 0x7f35fd7a4fa2 in start_thread /build/glibc-vjB4T1/glibc-2.28/nptl/pthread_create.c:486
    #13 0x7f35fd8c64ce in clone (/lib/x86_64-linux-gnu/libc.so.6+0xf94ce)

Now this test has no more leaks.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2021-06-15 16:49:02 +03:00 committed by Pekka Paalanen
parent 689e8b3c0a
commit ee1c1778bf

View file

@ -81,16 +81,19 @@ send_motion(struct client *client, const struct timespec *time, int x, int y)
}
static struct buffer *
surface_commit_color(struct client *client, struct wl_surface *surface,
surface_commit_color(struct client *client, struct surface *surface,
pixman_color_t *color, int width, int height)
{
struct buffer *buf;
buf = create_shm_buffer_a8r8g8b8(client, width, height);
fill_image_with_color(buf->image, color);
wl_surface_attach(surface, buf->proxy, 0, 0);
wl_surface_damage(surface, 0, 0, width, height);
wl_surface_commit(surface);
wl_surface_attach(surface->wl_surface, buf->proxy, 0, 0);
wl_surface_damage(surface->wl_surface, 0, 0, width, height);
wl_surface_commit(surface->wl_surface);
assert(!surface->buffer);
surface->buffer = buf;
return buf;
}
@ -125,14 +128,14 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter)
back_cursor_surface = create_test_surface(client);
/* Commit buffers for cursors. */
surface_commit_color(client, main_cursor_surface->wl_surface, &green, 25, 25);
surface_commit_color(client, back_cursor_surface->wl_surface, &magenta, 25, 25);
surface_commit_color(client, main_cursor_surface, &green, 25, 25);
surface_commit_color(client, back_cursor_surface, &magenta, 25, 25);
/* We need our own background surface so that we are able to change the cursor
* when the pointer leaves the main surface.
*/
weston_test_move_surface(client->test->weston_test, back_surface->wl_surface, 0, 0);
surface_commit_color(client, back_surface->wl_surface, &gray, 320, 240);
surface_commit_color(client, back_surface, &gray, 320, 240);
/* Set up the main surface. */
client->surface = main_surface;