Don't close the fd if libinput_add_fd() fails
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 22 Aug 2014 04:54:06 +0000 (14:54 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 26 Aug 2014 01:04:42 +0000 (11:04 +1000)
Let the caller decide what to do with the fd.

In the current code the caller can't know if the fd was closed on error since
we return NULL on malloc failure as well as on epoll_ctl() failure. In the
latter case the fd was closed, not in the former. The caller had to close
the fd anyway (and all three callers do), so drop closing the fd from this
function.

Found by Coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput.c

index 90b6a137d24a8cfd66314d9a88be8065fda1913d..ed5eba1757d2e746066ee0ca04115af1f7815299 100644 (file)
@@ -457,7 +457,6 @@ libinput_add_fd(struct libinput *libinput,
        ep.data.ptr = source;
 
        if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
-               close(source->fd);
                free(source);
                return NULL;
        }