util-lib: introdude _cleanup_ macros for kmod objects
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "module-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
@@ -77,7 +78,8 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
|
||||
|
||||
static int load_module(struct kmod_ctx *ctx, const char *m) {
|
||||
const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
|
||||
struct kmod_list *itr, *modlist = NULL;
|
||||
struct kmod_list *itr;
|
||||
_cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
|
||||
int r = 0;
|
||||
|
||||
log_debug("load: %s", m);
|
||||
@@ -92,7 +94,7 @@ static int load_module(struct kmod_ctx *ctx, const char *m) {
|
||||
}
|
||||
|
||||
kmod_list_foreach(itr, modlist) {
|
||||
struct kmod_module *mod;
|
||||
_cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
|
||||
int state, err;
|
||||
|
||||
mod = kmod_module_get_module(itr);
|
||||
@@ -120,12 +122,8 @@ static int load_module(struct kmod_ctx *ctx, const char *m) {
|
||||
r = err;
|
||||
}
|
||||
}
|
||||
|
||||
kmod_module_unref(mod);
|
||||
}
|
||||
|
||||
kmod_module_unref_list(modlist);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -218,7 +216,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int r, k;
|
||||
struct kmod_ctx *ctx;
|
||||
_cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;
|
||||
|
||||
r = parse_argv(argc, argv);
|
||||
if (r <= 0)
|
||||
@@ -280,7 +278,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
finish:
|
||||
kmod_unref(ctx);
|
||||
strv_free(arg_proc_cmdline_modules);
|
||||
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user