diff --git a/src/glx/glxext.c b/src/glx/glxext.c
index dc87fb9..462b89a 100644
--- a/src/glx/glxext.c
+++ b/src/glx/glxext.c
@@ -984,10 +984,11 @@ _X_HIDDEN GLubyte *
 __glXFlushRenderBuffer(struct glx_context * ctx, GLubyte * pc)
 {
    Display *const dpy = ctx->currentDpy;
-   xcb_connection_t *c = XGetXCBConnection(dpy);
    const GLint size = pc - ctx->buf;
 
    if ((dpy != NULL) && (size > 0)) {
+      xcb_connection_t *c = XGetXCBConnection(dpy);
+
       xcb_glx_render(c, ctx->currentContextTag, size,
                      (const uint8_t *) ctx->buf);
    }
