[PATCH libevdev 1/3] uinput: close the managed fd on error

David Herrmann dh.herrmann at gmail.com
Mon Aug 25 02:55:04 PDT 2014


Hi

On Mon, Aug 25, 2014 at 1:53 AM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> On Fri, Aug 22, 2014 at 04:58:14PM +0200, David Herrmann wrote:
>> Hi
>>
>> On Fri, Aug 22, 2014 at 4:56 AM, Peter Hutterer
>> <peter.hutterer at who-t.net> wrote:
>> > Using LIBEVDEV_UINPUT_OPEN_MANAGED can leak the fd if an error occurs after
>> > opening it.
>> >
>> > Found by Coverity.
>> >
>> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
>> > ---
>> >  libevdev/libevdev-uinput.c | 3 +++
>> >  1 file changed, 3 insertions(+)
>> >
>> > diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
>> > index c1b20e0..ea2b025 100644
>> > --- a/libevdev/libevdev-uinput.c
>> > +++ b/libevdev/libevdev-uinput.c
>> > @@ -279,6 +279,7 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
>> >         int rc;
>> >         struct uinput_user_dev uidev;
>> >         struct libevdev_uinput *new_device;
>> > +       int close_fd_on_error = (fd == LIBEVDEV_UINPUT_OPEN_MANAGED);
>>
>> You still need to fix the error-path exactly below into:
>>
>> if (!new_device) {
>>         rc = -ENOMEM;
>>         goto error;
>> }
>
> not necessary IMO, if the first memory allocation fails before we do
> anything else, returning immediately is easier here than handling the
> various exceptions.

Whoops, I somehow missed the fact that we only close the fd if it is
set to OPEN_MANAGED. In that case, it's not valid at this point, so we
can bail out early. Looks good:

Reviewed-by: David Herrmann <dh.herrmann at gmail.com>

Thanks
David


More information about the Input-tools mailing list