Check malloc return value and clean up resources if allocation fails.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
int i;
int n;
struct vertex *v;
- int rc;
+ int rc = 0;
array_init(&reverse, 3);
sz += vertex->mod->modnamesz - 1;
buf = malloc(sz + n * strlen(sep) + 1);
+ if (buf == NULL) {
+ rc = -ENOMEM;
+ goto out;
+ }
sz = 0;
for (i = reverse.count - 1; i >= 0; i--) {
ERR("Cycle detected: %s\n", buf);
free(buf);
+out:
array_free_array(&reverse);
- return 0;
+ return rc;
}
static int depmod_report_cycles_from_root(struct depmod *depmod, struct mod *root_mod,