mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-21 04:48:18 +02:00
tools/debug-tablet: don't leak the udev_device on open() failure
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1475>
This commit is contained in:
parent
e53c2141b3
commit
e88a16ea04
1 changed files with 6 additions and 9 deletions
|
|
@ -42,6 +42,7 @@
|
|||
#include "util-macros.h"
|
||||
#include "util-strings.h"
|
||||
|
||||
#include "libinput-util.h"
|
||||
#include "shared.h"
|
||||
|
||||
static volatile sig_atomic_t stop = 0;
|
||||
|
|
@ -259,8 +260,6 @@ static void
|
|||
handle_device_added(struct context *ctx, struct libinput_event *ev)
|
||||
{
|
||||
struct libinput_device *device = libinput_event_get_device(ev);
|
||||
struct udev_device *udev_device;
|
||||
const char *devnode;
|
||||
|
||||
if (ctx->device)
|
||||
return;
|
||||
|
|
@ -270,23 +269,21 @@ handle_device_added(struct context *ctx, struct libinput_event *ev)
|
|||
|
||||
ctx->device = libinput_device_ref(device);
|
||||
|
||||
udev_device = libinput_device_get_udev_device(device);
|
||||
_unref_(udev_device) *udev_device = libinput_device_get_udev_device(device);
|
||||
if (!udev_device)
|
||||
return;
|
||||
|
||||
devnode = udev_device_get_devnode(udev_device);
|
||||
const char *devnode = udev_device_get_devnode(udev_device);
|
||||
if (devnode) {
|
||||
int fd = open(devnode, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
_cleanup_(xclose) int fd =
|
||||
open(devnode, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd == -1)
|
||||
return;
|
||||
if (libevdev_new_from_fd(fd, &ctx->evdev) != 0) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
ctx->fds[1].fd = fd;
|
||||
ctx->fds[1].fd = steal_fd(&fd);
|
||||
}
|
||||
|
||||
udev_device_unref(udev_device);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue