If newly created module in kmod_module_new could not be added to hash,
return an error. Otherwise it is possible to create multiple independent
structs with the same name, which the hash set is supposed to prevent.
An error only occurs in out of memory conditions.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
_nonnull_all_ char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name);
_nonnull_all_ struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key);
-_nonnull_all_ void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key);
+_nonnull_all_ int kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key);
_nonnull_all_ void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key);
_nonnull_all_ const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx);
{
struct kmod_module *m;
size_t keylen;
+ int err;
m = kmod_pool_get_module(ctx, key);
if (m != NULL) {
}
m->refcount = 1;
- kmod_pool_add_module(ctx, m, m->hashkey);
+ err = kmod_pool_add_module(ctx, m, m->hashkey);
+ if (err < 0) {
+ free(m);
+ return err;
+ }
*mod = m;
return 0;
return mod;
}
-void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key)
+int kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key)
{
DBG(ctx, "add %p key='%s'\n", mod, key);
- hash_add(ctx->modules_by_name, key, mod);
+ return hash_add(ctx->modules_by_name, key, mod);
}
void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key)