[waffle] [PATCH 1/3] gbm: cleanup memory leaks
Emil Velikov
emil.l.velikov at gmail.com
Sun Jun 1 07:12:00 PDT 2014
Avoid leaking udev and udev_enumerate. Spotted while
searching for invalid memory access in the wgl platform.
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/gbm/wgbm_display.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/waffle/gbm/wgbm_display.c b/src/waffle/gbm/wgbm_display.c
index 070ce70..be5e83f 100644
--- a/src/waffle/gbm/wgbm_display.c
+++ b/src/waffle/gbm/wgbm_display.c
@@ -69,7 +69,7 @@ wgbm_get_default_fd_for_pattern(const char *pattern)
{
struct udev *ud;
struct udev_enumerate *en;
- struct udev_list_entry *entry;
+ struct udev_list_entry *devices, *entry;
const char *path, *filename;
struct udev_device *device;
int fd;
@@ -79,18 +79,23 @@ wgbm_get_default_fd_for_pattern(const char *pattern)
udev_enumerate_add_match_subsystem(en, "drm");
udev_enumerate_add_match_sysname(en, pattern);
udev_enumerate_scan_devices(en);
+ devices = udev_enumerate_get_list_entry(en);
- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(en)) {
+ udev_list_entry_foreach(entry, devices) {
path = udev_list_entry_get_name(entry);
device = udev_device_new_from_syspath(ud, path);
filename = udev_device_get_devnode(device);
fd = open(filename, O_RDWR | O_CLOEXEC);
udev_device_unref(device);
if (fd >= 0) {
+ udev_enumerate_unref(en);
+ udev_unref(ud);
return fd;
}
}
+ udev_enumerate_unref(en);
+ udev_unref(ud);
return -1;
}
--
1.9.3
More information about the waffle
mailing list