From e35ef44ebe788aaffd1f6910750492bacaba7b6f Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Tue, 5 Aug 2014 10:46:11 -0400 Subject: test: use _cleanup_ attribute Signed-off-by: Anthony G. Basile --- test/test-libudev.c | 8 ++++---- test/test-udev.c | 16 +++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/test-libudev.c b/test/test-libudev.c index 0e1202b449..912b61396a 100644 --- a/test/test-libudev.c +++ b/test/test-libudev.c @@ -30,6 +30,7 @@ #include #include "libudev.h" +#include "udev-util.h" #include "util.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -116,7 +117,7 @@ static void print_device(struct udev_device *device) { } static int test_device(struct udev *udev, const char *syspath) { - struct udev_device *device; + _cleanup_udev_device_unref_ struct udev_device *device; printf("looking at device: %s\n", syspath); device = udev_device_new_from_syspath(udev, syspath); @@ -125,12 +126,12 @@ static int test_device(struct udev *udev, const char *syspath) { return -1; } print_device(device); - udev_device_unref(device); + return 0; } static int test_device_parents(struct udev *udev, const char *syspath) { - struct udev_device *device; + _cleanup_udev_device_unref_ struct udev_device *device; struct udev_device *device_parent; printf("looking at device: %s\n", syspath); @@ -151,7 +152,6 @@ static int test_device_parents(struct udev *udev, const char *syspath) { print_device(device_parent); device_parent = udev_device_get_parent(device_parent); } while (device_parent != NULL); - udev_device_unref(device); return 0; } diff --git a/test/test-udev.c b/test/test-udev.c index fd4388a678..b3ff9a94cc 100644 --- a/test/test-udev.c +++ b/test/test-udev.c @@ -31,9 +31,10 @@ #include #include #include -#include +#include "missing.h" #include "udev.h" +#include "udev-util.h" #ifndef HAVE_UNSHARE #include @@ -91,10 +92,10 @@ out: } int main(int argc, char *argv[]) { - struct udev *udev = NULL; - struct udev_event *event = NULL; - struct udev_device *dev = NULL; - struct udev_rules *rules = NULL; + _cleanup_udev_unref_ struct udev *udev = NULL; + _cleanup_udev_event_unref_ struct udev_event *event = NULL; + _cleanup_udev_device_unref_ struct udev_device *dev = NULL; + _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL; char syspath[UTIL_PATH_SIZE]; const char *devpath; const char *action; @@ -169,10 +170,7 @@ int main(int argc, char *argv[]) { out: if (event != NULL && event->fd_signal >= 0) close(event->fd_signal); - udev_event_unref(event); - udev_device_unref(dev); - udev_rules_unref(rules); label_finish(); - udev_unref(udev); + return err ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf