fix:no more leaks possible

This commit is contained in:
jonathan santis
2025-05-15 13:46:03 +02:00
parent 00190b2354
commit 77f5c5ac2c
2 changed files with 9 additions and 4 deletions

View File

@@ -165,7 +165,8 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
char *keyName=NULL;
char *keyValue=NULL;
sectionName = malloc(MAX_LEN_SECTIONNAME);
memset(sectionName,0,MAX_LEN_SECTIONNAME);
//read buffer line by line
char *token;
@@ -175,7 +176,6 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
switch(state)
{
case ST_INIT:
sectionName = malloc(MAX_LEN_SECTIONNAME);
printf("token(line): %s\n",token);
if((ret=checkSection(token,'[',']',&sectionName))==FOUND_SECTION)
@@ -196,7 +196,6 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
ptr_entry[i].sectionName = strdup(sectionName);
ptr_entry[i].keyValue= strdup(keyValue);
ptr_entry[i].keyName = strdup(keyName);
free(sectionName);
free(keyName);
free(keyValue);
if(i<configSizeCount-1)
@@ -211,6 +210,8 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int
state = ST_FOUND_SECTION;
}
else {
free(keyName);
free(keyValue);
state = ST_SKIP_READ;
}
break;