tests: release memory before error exits.

this makes it easier to valgrind the error cases as well.
This commit is contained in:
Gustavo Sverzut Barbieri 2011-12-04 21:18:21 -02:00 committed by Lucas De Marchi
parent 69f9dd4369
commit 8226058343
4 changed files with 8 additions and 2 deletions

View 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);

View 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);

View 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);
}

View 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);