fix:no more leaks possible
This commit is contained in:
7
config.c
7
config.c
@@ -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,'[',']',§ionName))==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;
|
||||
|
||||
Reference in New Issue
Block a user