From bb717a3be563c1bf00420026ba932bcb6ad51d41 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Wed, 2 Sep 2009 23:11:22 +0000 Subject: [PATCH] less malloc and memory fragmentation. not that important, but an easy improvement does not hurt. SVN revision: 42195 --- legacy/eina/src/lib/eina_module.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/legacy/eina/src/lib/eina_module.c b/legacy/eina/src/lib/eina_module.c index 91019f27f2..9207799a49 100644 --- a/legacy/eina/src/lib/eina_module.c +++ b/legacy/eina/src/lib/eina_module.c @@ -84,9 +84,9 @@ static int EINA_MODULE_LOG_DOM = -1; struct _Eina_Module { - char *file; void *handle; int ref; + const char file[]; }; typedef struct _Dir_List_Get_Cb_Data @@ -291,13 +291,20 @@ eina_module_shutdown(void) EAPI Eina_Module *eina_module_new(const char *file) { Eina_Module *m; + size_t len; EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); /* TODO check that the file exists. Update doc too */ - m = malloc(sizeof(Eina_Module)); - /* TODO add the magic */ - m->file = strdup(file); + len = strlen(file); + EINA_SAFETY_ON_FALSE_RETURN_VAL(len > 0, NULL); + + m = malloc(sizeof(Eina_Module) + len + 1); + if (!m) { + ERR("could not malloc(%lu)\n", sizeof(Eina_Module) + len + 1); + return NULL; + } + memcpy((char *)m->file, file, len + 1); m->ref = 0; m->handle = NULL; DBG("m=%p, file=%s\n", m, file); @@ -327,7 +334,6 @@ EAPI Eina_Bool eina_module_free(Eina_Module *m) if (eina_module_unload(m) == EINA_FALSE) return EINA_FALSE; } - free(m->file); free(m); return EINA_TRUE; }