On Mon, Apr 25, 2016 at 05:57:51PM +0200, Carlos Olmedo Escobar wrote:
> Signed-off-by: Carlos Olmedo Escobar <[email protected]>
> ---
>  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;

this isn't needed. events is a copy of the libinput->events pointer, so if
'events' cannot be reallocated and is NULL, we discard that copy and exit
the function without other changes. libinput->events thus stays at the
original value.

This patch merely protects 'events' but that isn't used in the realloc
failure anyway.

Cheers,
   Peter

>  
>               if (libinput->events_count > 0 && libinput->events_in == 0) {
>                       libinput->events_in = libinput->events_len;
> -- 
> 2.8.1
_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to