]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
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 bbff8784ace3a12d95d93ae21934269622a8ea1a..fb585619fd6ef5f07f72723459a9911a94c50d5a 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 29a7d3c90d318d01fce444f838cf67f8eb358b92..5b2762886c712c3e48535a5651e2241883bf0827 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 7a7bc5b442dbe96241d324728839a609377ecf1b..e1b9fb4f21664e2b46daacee18e543700aee2195 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 c3585be57153d41605404a9b9cbc11b096d0a8ee..5e3fa496e27a4b162f657fd76fa150f59cd1d012 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);