this makes it easier to valgrind the error cases as well.
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);
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);
err = kmod_loaded_get_list(ctx, &list);
if (err < 0) {
fprintf(stderr, "%s\n", strerror(-err));
+ kmod_unref(ctx);
exit(EXIT_FAILURE);
}
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);