summaryrefslogtreecommitdiff
path: root/src/modules.c
diff options
context:
space:
mode:
authorgeniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-12-30 17:12:06 +0000
committergeniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-12-30 17:12:06 +0000
commit35096dbb8ce8ea359a0e929f3312cf1299c8ab20 (patch)
tree98cb855ebab1c1f9bdc7dfa8da4125791b96a0a0 /src/modules.c
parentae23e2f86aca05ab734d731e6c2e456d4d89a8c0 (diff)
BUILD : 1.7.6 (515) BUGS : 261 NOTES : Fixed a few memleaks with moduleData functions returning early, and fixed the list handling with deleting moduleData (thanks DrStein)
git-svn-id: svn://svn.anope.org/anope/trunk@515 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@369 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/modules.c')
-rw-r--r--src/modules.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/modules.c b/src/modules.c
index 64304e4af..4fa4c2c77 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -1818,12 +1818,18 @@ int moduleDataDebug(ModuleData ** md)
**/
int moduleAddData(ModuleData ** md, char *key, char *value)
{
+ /* Do we really need this sstrdup here? Why can't we just use
+ * mod_current_module_name itself inside this function? It's not like
+ * we're changing it or anything, we just pass it to yet another
+ * sstrdup() somewhere down there.... -GD
+ */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *newData = NULL;
ModuleData *tmp = *md;
if (!key || !value) {
alog("A module tried to use ModuleAddData() with one ore more NULL arguments... returning");
+ free(mod_name);
return MOD_ERR_PARAMS;
}
@@ -1837,6 +1843,7 @@ int moduleAddData(ModuleData ** md, char *key, char *value)
newData = malloc(sizeof(ModuleData));
if (!newData) {
+ free(mod_name);
return MOD_ERR_MEMORY;
}
@@ -1867,7 +1874,7 @@ int moduleAddData(ModuleData ** md, char *key, char *value)
**/
char *moduleGetData(ModuleData ** md, char *key)
{
-
+ /* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
@@ -1883,8 +1890,8 @@ char *moduleGetData(ModuleData ** md, char *key)
}
while (current) {
- if ((stricmp(current->moduleName, mod_name) == 0)
- && (stricmp(current->key, key) == 0)) {
+ if ((stricmp(current->moduleName, mod_name) == 0) && (stricmp(current->key, key) == 0)) {
+ free(mod_name);
return sstrdup(current->value);
}
current = current->next;
@@ -1901,6 +1908,7 @@ char *moduleGetData(ModuleData ** md, char *key)
**/
void moduleDelData(ModuleData ** md, char *key)
{
+ /* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
ModuleData *prev = NULL;
@@ -1915,8 +1923,7 @@ void moduleDelData(ModuleData ** md, char *key)
if (key) {
while (current) {
next = current->next;
- if ((stricmp(current->moduleName, mod_name) == 0)
- && (stricmp(current->key, key) == 0)) {
+ if ((stricmp(current->moduleName, mod_name) == 0) && (stricmp(current->key, key) == 0)) {
if (prev) {
prev->next = current->next;
} else {
@@ -1927,8 +1934,9 @@ void moduleDelData(ModuleData ** md, char *key)
free(current->value);
current->next = NULL;
free(current);
+ } else {
+ prev = current;
}
- prev = current;
current = next;
}
}
@@ -1943,6 +1951,7 @@ void moduleDelData(ModuleData ** md, char *key)
**/
void moduleDelAllData(ModuleData ** md)
{
+ /* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
ModuleData *prev = NULL;
@@ -1967,8 +1976,9 @@ void moduleDelAllData(ModuleData ** md)
free(current->value);
current->next = NULL;
free(current);
+ } else {
+ prev = current;
}
- prev = current;
current = next;
}
free(mod_name);