From: Lucas De Marchi Date: Tue, 27 Dec 2011 06:51:05 +0000 (-0200) Subject: Allow to internally get dependencies without copying list X-Git-Tag: v3~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b72f74b5dd17daf6d52672f26fbd8051fd106789;p=thirdparty%2Fkmod.git Allow to internally get dependencies without copying list --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 7793062c..4e19af92 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -541,6 +541,25 @@ KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) return 0; } +static const struct kmod_list *module_get_dependencies_noref(const struct kmod_module *mod) +{ + if (!mod->init.dep) { + /* lazy init */ + char *line = kmod_search_moddep(mod->ctx, mod->name); + + if (line == NULL) + return NULL; + + kmod_module_parse_depline((struct kmod_module *)mod, line); + free(line); + + if (!mod->init.dep) + return NULL; + } + + return mod->dep; +} + /** * kmod_module_get_dependencies: * @mod: kmod module @@ -560,19 +579,7 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_dependencies(const struct kmod_mod if (mod == NULL) return NULL; - if (!mod->init.dep) { - /* lazy init */ - char *line = kmod_search_moddep(mod->ctx, mod->name); - - if (line == NULL) - return NULL; - - kmod_module_parse_depline((struct kmod_module *)mod, line); - free(line); - - if (!mod->init.dep) - return NULL; - } + module_get_dependencies_noref(mod); kmod_list_foreach(l, mod->dep) { l_new = kmod_list_append(list_new, kmod_module_ref(l->data));