modules-load: fix memory leak when bailing out
Suggested-by: Mauro Dreissig <mukadr@gmail.com>
This commit is contained in:
parent
5fe25affc0
commit
c007bb1b4d
|
@ -64,7 +64,8 @@ static int add_modules(const char *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_proc_cmdline(void) {
|
static int parse_proc_cmdline(void) {
|
||||||
char *line, *w, *state;
|
char _cleanup_free_ *line = NULL;
|
||||||
|
char *w, *state;
|
||||||
int r;
|
int r;
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
|
@ -78,38 +79,30 @@ static int parse_proc_cmdline(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(w, l, line, state) {
|
FOREACH_WORD_QUOTED(w, l, line, state) {
|
||||||
char *word;
|
char _cleanup_free_ *word;
|
||||||
|
|
||||||
word = strndup(w, l);
|
word = strndup(w, l);
|
||||||
if (!word) {
|
if (!word)
|
||||||
r = -ENOMEM;
|
return log_oom();
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startswith(word, "modules-load=")) {
|
if (startswith(word, "modules-load=")) {
|
||||||
|
|
||||||
r = add_modules(word + 13);
|
r = add_modules(word + 13);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
return r;
|
||||||
|
|
||||||
} else if (startswith(word, "rd.modules-load=")) {
|
} else if (startswith(word, "rd.modules-load=")) {
|
||||||
|
|
||||||
if (in_initrd()) {
|
if (in_initrd()) {
|
||||||
r = add_modules(word + 16);
|
r = add_modules(word + 16);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(word);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = 0;
|
return 0;
|
||||||
|
|
||||||
finish:
|
|
||||||
free(line);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_module(struct kmod_ctx *ctx, const char *m) {
|
static int load_module(struct kmod_ctx *ctx, const char *m) {
|
||||||
|
|
Loading…
Reference in New Issue