[PATCH xserver 17/19] loader: Remove unused path and name from ModuleDescPtr

Adam Jackson ajax at redhat.com
Mon Jan 23 19:32:31 UTC 2017


Just a waste of memory. Path was never referenced at all, and name was
only used when unloading the module; we can just as well get the
module's internal idea of its name from VersionInfo.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 hw/xfree86/loader/loaderProcs.h |  2 --
 hw/xfree86/loader/loadmod.c     | 31 +++++++++----------------------
 2 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index 84ed103..8b16cb7 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -59,8 +59,6 @@ typedef struct module_desc {
     struct module_desc *child;
     struct module_desc *sib;
     struct module_desc *parent;
-    char *name;
-    char *path;
     void *handle;
     ModuleSetupProc SetupProc;
     ModuleTearDownProc TearDownProc;
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index fc982c7..cb86925 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -600,17 +600,6 @@ LoadSubModule(void *_parent, const char *module,
     return submod;
 }
 
-static ModuleDescPtr
-NewModuleDesc(const char *name)
-{
-    ModuleDescPtr mdp = calloc(1, sizeof(ModuleDesc));
-
-    if (mdp)
-        mdp->name = xstrdup(name);
-
-    return mdp;
-}
-
 ModuleDescPtr
 DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
 {
@@ -619,7 +608,7 @@ DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
     if (!mod)
         return NULL;
 
-    ret = NewModuleDesc(mod->name);
+    ret = calloc(1, sizeof(ModuleDesc));
     if (ret == NULL)
         return NULL;
 
@@ -632,7 +621,6 @@ DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent)
     ret->sib = DuplicateModule(mod->sib, parent);
     ret->parent = parent;
     ret->VersionInfo = mod->VersionInfo;
-    ret->path = strdup(mod->path);
 
     return ret;
 }
@@ -726,7 +714,7 @@ LoadModule(const char *module, void *options, const XF86ModReqInfo *modreq,
             *errmaj = LDR_BADUSAGE;
         goto LoadModule_fail;
     }
-    ret = NewModuleDesc(name);
+    ret = calloc(1, sizeof(ModuleDesc));
     if (!ret) {
         if (errmaj)
             *errmaj = LDR_NOMEM;
@@ -773,7 +761,6 @@ LoadModule(const char *module, void *options, const XF86ModReqInfo *modreq,
     ret->handle = LoaderOpen(found, errmaj);
     if (ret->handle == NULL)
         goto LoadModule_fail;
-    ret->path = strdup(found);
 
     /* drop any explicit suffix from the module name */
     p = strchr(name, '.');
@@ -857,31 +844,31 @@ void
 UnloadModule(void *_mod)
 {
     ModuleDescPtr mod = _mod;
+    const char *name;
 
     if (mod == (ModuleDescPtr) 1)
         return;
 
-    if (mod == NULL || mod->name == NULL)
+    if (mod == NULL)
         return;
 
+    name = mod->VersionInfo->modname;
+
     if (mod->parent)
-        LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n",
-                              mod->name);
+        LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name);
     else
-        LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", mod->name);
+        LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", name);
 
     if (mod->TearDownData != ModuleDuplicated) {
         if ((mod->TearDownProc) && (mod->TearDownData))
             mod->TearDownProc(mod->TearDownData);
-        LoaderUnload(mod->name, mod->handle);
+        LoaderUnload(name, mod->handle);
     }
 
     if (mod->child)
         UnloadModule(mod->child);
     if (mod->sib)
         UnloadModule(mod->sib);
-    free(mod->path);
-    free(mod->name);
     free(mod);
 }
 
-- 
2.9.3



More information about the xorg-devel mailing list