From c0ac1ef9f298fdb8be08c83ce37157356eaf19e2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 24 Dec 2013 13:50:10 +1000 Subject: [PATCH] Always allocate an event queue On the typical setup we have at least 3 events pending as soon as we hook it up (seat added, device added, capability). In the udev case we get up to > 64 events without even having input events on my laptop with only two extra devices connected. So always allocate an event buffer to avoid spurious resizing. Signed-off-by: Peter Hutterer --- src/libinput.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 95976f7f..06b72632 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -372,6 +372,13 @@ libinput_init(struct libinput *libinput, if (libinput->epoll_fd < 0) return -1; + libinput->events_len = 4; + libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events)); + if (!libinput->events) { + close(libinput->epoll_fd); + return -1; + } + libinput->interface = interface; libinput->user_data = user_data; list_init(&libinput->source_destroy_list); @@ -869,10 +876,7 @@ libinput_post_event(struct libinput *libinput, events_count++; if (events_count > events_len) { - if (events_len == 0) - events_len = 4; - else - events_len *= 2; + events_len *= 2; events = realloc(events, events_len * sizeof *events); if (!events) { fprintf(stderr, "Failed to reallocate event ring "