struct index_file *idx;
struct index_value *realnames, *realname;
+ assert(*list == NULL);
+
if (ctx->indexes[index_number] != NULL) {
DBG(ctx, "use mmapped index '%s' for name=%s\n",
index_files[index_number].fn, name);
for (realname = realnames; realname; realname = realname->next) {
struct kmod_module *mod;
+ struct kmod_list *node;
err = kmod_module_new_from_alias(ctx, name, realname->value, &mod);
if (err < 0) {
goto fail;
}
- *list = kmod_list_append(*list, mod);
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
+ err = -ENOMEM;
+ goto fail;
+ }
+ *list = node;
nmatch++;
}
return nmatch;
fail:
- *list = kmod_list_remove_n_latest(*list, nmatch);
+ kmod_list_release(*list, kmod_module_unref);
index_values_free(realnames);
return err;
}
struct kmod_list *l;
int ret;
- assert(*list == NULL);
-
ret = kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_BUILTIN_ALIAS,
name, list);
if (lookup_builtin_file(ctx, name)) {
struct kmod_module *mod;
+ struct kmod_list *node;
int err;
err = kmod_module_new_from_name(ctx, name, &mod);
/* already mark it as builtin since it's being created from
* this index */
kmod_module_set_builtin(mod, true);
- *list = kmod_list_append(*list, mod);
- if (*list == NULL)
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
return -ENOMEM;
+ }
+ *list = node;
}
return 0;
char *line;
int n = 0;
+ assert(*list == NULL);
+
/*
* Module names do not contain ':'. Return early if we know it will
* not be found.
line = kmod_search_moddep(ctx, name);
if (line != NULL) {
struct kmod_module *mod;
+ struct kmod_list *node;
n = kmod_module_new_from_name(ctx, name, &mod);
if (n < 0) {
goto finish;
}
- *list = kmod_list_append(*list, mod);
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
+ n = -ENOMEM;
+ goto finish;
+ }
+ *list = node;
kmod_module_parse_depline(mod, line);
}
struct kmod_list *l;
int err, nmatch = 0;
+ assert(*list == NULL);
+
kmod_list_foreach(l, config->aliases) {
const char *aliasname = kmod_alias_get_name(l);
const char *modname = kmod_alias_get_modname(l);
if (fnmatch(aliasname, name, 0) == 0) {
struct kmod_module *mod;
+ struct kmod_list *node;
err = kmod_module_new_from_alias(ctx, aliasname, modname, &mod);
if (err < 0) {
goto fail;
}
- *list = kmod_list_append(*list, mod);
+ node = kmod_list_append(*list, mod);
+ if (node == NULL) {
+ ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
+ err = -ENOMEM;
+ goto fail;
+ }
+ *list = node;
nmatch++;
}
}
return nmatch;
fail:
- *list = kmod_list_remove_n_latest(*list, nmatch);
+ kmod_list_release(*list, kmod_module_unref);
return err;
}
struct kmod_list *l, *node;
int err, nmatch = 0;
+ assert(*list == NULL);
+
kmod_list_foreach(l, config->install_commands) {
const char *modname = kmod_command_get_modname(l);
node = kmod_list_append(*list, mod);
if (node == NULL) {
ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
return -ENOMEM;
}
node = kmod_list_append(*list, mod);
if (node == NULL) {
ERR(ctx, "out of memory\n");
+ kmod_module_unref(mod);
return -ENOMEM;
}
}
DEFINE_TEST(test_list_prev, .description = "test list prev");
-static int test_list_remove_n_latest(const struct test *t)
-{
- struct kmod_list *list = NULL, *l;
- int i;
- const char *v[] = { "v1", "v2", "v3", "v4", "v5" };
- const int N = ARRAY_SIZE(v), M = N / 2;
-
- for (i = 0; i < N; i++)
- list = kmod_list_append(list, v[i]);
- assert_return(len(list) == N, EXIT_FAILURE);
-
- list = kmod_list_remove_n_latest(list, M);
- assert_return(len(list) == N - M, EXIT_FAILURE);
-
- i = 0;
- kmod_list_foreach(l, list) {
- assert_return(l->data == v[i], EXIT_FAILURE);
- i++;
- }
-
- kmod_list_remove_all(list);
-
- return 0;
-}
-DEFINE_TEST(test_list_remove_n_latest,
- .description = "test list function to remove n latest elements");
-
static int test_list_remove_data(const struct test *t)
{
struct kmod_list *list = NULL, *l;