From ebe86fdaa9aa13de3d1952c5d7a62bf36e834455 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 30 Mar 2016 14:31:18 +0100 Subject: test/dri2-race: Don't leak the Display after detecting the race Signed-off-by: Chris Wilson --- test/dri2-race.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/dri2-race.c b/test/dri2-race.c index 4e5187c6..79dc9c49 100644 --- a/test/dri2-race.c +++ b/test/dri2-race.c @@ -631,15 +631,15 @@ static void race_client(int width, int height, printf("DRI2SwapBuffers(divisor=%d)", divisors[n]); loop = 256 >> ffs(divisors[n]); do { - Display *dpy; + Display *dpy = XOpenDisplay(NULL); Window win; if (error_get()) { + XCloseDisplay(dpy); printf("+"); fflush(stdout); continue; } - dpy = XOpenDisplay(NULL); win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, DefaultDepth(dpy, DefaultScreen(dpy)), @@ -653,11 +653,10 @@ static void race_client(int width, int height, DRI2CreateDrawable(dpy, win); free(DRI2GetBuffers(dpy, win, &width, &height, attachments, nattachments, &count)); - if (count != nattachments) - return; - - for (count = 0; count < loop; count++) - DRI2SwapBuffers(dpy, win, 0, divisors[n], count & (divisors[n]-1)); + if (count == nattachments) { + for (count = 0; count < loop; count++) + DRI2SwapBuffers(dpy, win, 0, divisors[n], count & (divisors[n]-1)); + } XFlush(dpy); XKillClient(mgr, win); @@ -675,15 +674,15 @@ static void race_client(int width, int height, printf("xcb_dri2_swap_buffers(divisor=%d)", divisors[n]); loop = 256 >> ffs(divisors[n]); do { - Display *dpy; + Display *dpy = XOpenDisplay(NULL); Window win; if (error_get()) { + XCloseDisplay(dpy); printf("+"); fflush(stdout); continue; } - dpy = XOpenDisplay(NULL); win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, DefaultDepth(dpy, DefaultScreen(dpy)), @@ -697,11 +696,10 @@ static void race_client(int width, int height, DRI2CreateDrawable(dpy, win); free(DRI2GetBuffers(dpy, win, &width, &height, attachments, nattachments, &count)); - if (count != nattachments) - return; - - for (count = 0; count < loop; count++) - swap_buffers(dpy, win, divisors[n], attachments, nattachments); + if (count == nattachments) { + for (count = 0; count < loop; count++) + swap_buffers(dpy, win, divisors[n], attachments, nattachments); + } XFlush(dpy); XKillClient(mgr, win); @@ -719,17 +717,17 @@ static void race_client(int width, int height, printf("DRI2WaitMsc(divisor=%d)", divisors[n]); loop = 256 >> ffs(divisors[n]); do { + Display *dpy = XOpenDisplay(NULL); uint64_t ignore, msc; - Display *dpy; xcb_connection_t *c; Window win; if (error_get()) { + XCloseDisplay(dpy); printf("+"); fflush(stdout); continue; } - dpy = XOpenDisplay(NULL); win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, DefaultDepth(dpy, DefaultScreen(dpy)), -- cgit v1.2.1