From: Michael Stapelberg Date: Sun, 31 Jul 2011 15:46:01 +0000 (+0200) Subject: Bugfix: Allocate 32 bytes for xcb_send_event, it always copies 32 bytes X-Git-Tag: 4.0~14^2~17 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1e0033bce4;p=i3%2Fi3 Bugfix: Allocate 32 bytes for xcb_send_event, it always copies 32 bytes Fixes an 'uninitialized memory' error in valgrind --- diff --git a/src/xcb.c b/src/xcb.c index b88b7673..115fafe9 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -167,23 +167,29 @@ void xcb_draw_rect(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext * */ void fake_configure_notify(xcb_connection_t *conn, Rect r, xcb_window_t window) { - xcb_configure_notify_event_t generated_event; + /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. + * In order to properly initialize these bytes, we allocate 32 bytes even + * though we only need less for an xcb_configure_notify_event_t */ + void *event = scalloc(32); + xcb_configure_notify_event_t *generated_event = event; - generated_event.event = window; - generated_event.window = window; - generated_event.response_type = XCB_CONFIGURE_NOTIFY; + generated_event->event = window; + generated_event->window = window; + generated_event->response_type = XCB_CONFIGURE_NOTIFY; - generated_event.x = r.x; - generated_event.y = r.y; - generated_event.width = r.width; - generated_event.height = r.height; + generated_event->x = r.x; + generated_event->y = r.y; + generated_event->width = r.width; + generated_event->height = r.height; - generated_event.border_width = 0; - generated_event.above_sibling = XCB_NONE; - generated_event.override_redirect = false; + generated_event->border_width = 0; + generated_event->above_sibling = XCB_NONE; + generated_event->override_redirect = false; xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&generated_event); xcb_flush(conn); + + free(event); } /*