Skip to content

Commit

Permalink
loadHashTable(): fix memory leak in error code path (#6661)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 5, 2022
1 parent 41a8871 commit 8a0b2cd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mapfile.c
Expand Up @@ -2171,7 +2171,6 @@ static void writeExpression(FILE *stream, int indent, const char *name, expressi

int loadHashTable(hashTableObj *ptable)
{
char *key=NULL, *data=NULL;
assert(ptable);

for(;;) {
Expand All @@ -2182,14 +2181,19 @@ int loadHashTable(hashTableObj *ptable)
case(END):
return(MS_SUCCESS);
case(MS_STRING):
key = msStrdup(msyystring_buffer); /* the key is *always* a string */
if(getString(&data) == MS_FAILURE) return(MS_FAILURE);
{
char* data = NULL;
char* key = msStrdup(msyystring_buffer); /* the key is *always* a string */
if(getString(&data) == MS_FAILURE) {
free(key);
return(MS_FAILURE);
}
msInsertHashTable(ptable, key, data);

free(key);
free(data);
data=NULL;
break;
}
default:
msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadHashTable()", msyystring_buffer, msyylineno );
return(MS_FAILURE);
Expand Down

0 comments on commit 8a0b2cd

Please sign in to comment.