From 8226058343ac9634b9af0999c9fce84dc71e1bb9 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Sun, 4 Dec 2011 21:18:21 -0200 Subject: [PATCH] tests: release memory before error exits. this makes it easier to valgrind the error cases as well. --- test/test-insmod.c | 4 +++- test/test-lookup.c | 1 + test/test-rmmod.c | 1 + test/test-rmmod2.c | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test-insmod.c b/test/test-insmod.c index bbff878..fb58561 100644 --- a/test/test-insmod.c +++ b/test/test-insmod.c @@ -29,8 +29,10 @@ int main(int argc, char *argv[]) printf("libkmod version %s\n", VERSION); err = kmod_module_new_from_path(ctx, path, &mod); - if (err < 0) + if (err < 0) { + kmod_unref(ctx); exit(EXIT_FAILURE); + } printf("Trying insmod '%s'\n", path); err = kmod_module_insert_module(mod, 0); diff --git a/test/test-lookup.c b/test/test-lookup.c index 29a7d3c..5b27628 100644 --- a/test/test-lookup.c +++ b/test/test-lookup.c @@ -40,6 +40,7 @@ int main(int argc, char *argv[]) kmod_list_foreach(l, list) { struct kmod_module *mod = kmod_module_get_module(l); printf("\t%s\n", kmod_module_get_name(mod)); + kmod_module_unref(mod); } kmod_module_unref_list(list); diff --git a/test/test-rmmod.c b/test/test-rmmod.c index 7a7bc5b..e1b9fb4 100644 --- a/test/test-rmmod.c +++ b/test/test-rmmod.c @@ -27,6 +27,7 @@ int main(int argc, char *argv[]) err = kmod_loaded_get_list(ctx, &list); if (err < 0) { fprintf(stderr, "%s\n", strerror(-err)); + kmod_unref(ctx); exit(EXIT_FAILURE); } diff --git a/test/test-rmmod2.c b/test/test-rmmod2.c index c3585be..5e3fa49 100644 --- a/test/test-rmmod2.c +++ b/test/test-rmmod2.c @@ -29,8 +29,10 @@ int main(int argc, char *argv[]) printf("libkmod version %s\n", VERSION); err = kmod_module_new_from_name(ctx, modname, &mod); - if (err < 0) + if (err < 0) { + kmod_unref(ctx); exit(EXIT_FAILURE); + } printf("Trying to remove '%s'\n", modname); kmod_module_remove_module(mod, 0); -- 2.7.4