From 9eaad1f63aecf743b6aa6f1191c43f72b2d52d38 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 1 Dec 2011 17:18:24 -0200 Subject: [PATCH] Allow path_to_modname to operate locally withou alloc --- libkmod/libkmod-module.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index f28678f0..f864e563 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -46,7 +46,7 @@ struct kmod_module { const char *name; }; -static char *path_to_modname(const char *path) +static char *path_to_modname(const char *path, bool alloc) { char *modname; char *c; @@ -55,7 +55,9 @@ static char *path_to_modname(const char *path) if (modname == NULL || modname[0] == '\0') return NULL; - modname = strdup(modname); + if (alloc) + modname = strdup(modname); + for (c = modname; *c != '\0' && *c != '.'; c++) { if (*c == '-') *c = '_'; @@ -68,7 +70,7 @@ static char *path_to_modname(const char *path) static const char *get_modname(struct kmod_module *mod) { if (mod->name == NULL) - mod->name = path_to_modname(mod->path); + mod->name = path_to_modname(mod->path, true); return mod->name; } -- 2.47.2