tests: release memory before error exits.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sun, 4 Dec 2011 23:18:21 +0000 (21:18 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Mon, 5 Dec 2011 03:45:21 +0000 (01:45 -0200)
this makes it easier to valgrind the error cases as well.

test/test-insmod.c
test/test-lookup.c
test/test-rmmod.c
test/test-rmmod2.c

index bbff878..fb58561 100644 (file)
@@ -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);
index 29a7d3c..5b27628 100644 (file)
@@ -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);
index 7a7bc5b..e1b9fb4 100644 (file)
@@ -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);
        }
 
index c3585be..5e3fa49 100644 (file)
@@ -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);