[PATCH libinput] Check realloc() return value before assigning.

Carlos Olmedo Escobar carlos.olmedo.e at gmail.com
Mon Apr 25 15:57:51 UTC 2016


Signed-off-by: Carlos Olmedo Escobar <carlos.olmedo.e at gmail.com>
---
 src/libinput.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/libinput.c b/src/libinput.c
index bcd0dcd..e5a1ae4 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -2578,6 +2578,7 @@ libinput_post_event(struct libinput *libinput,
 		    struct libinput_event *event)
 {
 	struct libinput_event **events = libinput->events;
+	struct libinput_event **events_temp;
 	size_t events_len = libinput->events_len;
 	size_t events_count = libinput->events_count;
 	size_t move_len;
@@ -2590,13 +2591,14 @@ libinput_post_event(struct libinput *libinput,
 	events_count++;
 	if (events_count > events_len) {
 		events_len *= 2;
-		events = realloc(events, events_len * sizeof *events);
-		if (!events) {
+		events_temp = realloc(events, events_len * sizeof *events);
+		if (!events_temp) {
 			log_error(libinput,
 				  "Failed to reallocate event ring buffer. "
 				  "Events may be discarded\n");
 			return;
 		}
+		events = events_temp;
 
 		if (libinput->events_count > 0 && libinput->events_in == 0) {
 			libinput->events_in = libinput->events_len;
-- 
2.8.1



More information about the wayland-devel mailing list