Fix memory leak when attempting to parse something that isn't JSON.

This commit is contained in:
Jordan Bancino 2022-12-14 14:54:06 +00:00
parent 5255c3f773
commit 708a840ec0

View file

@ -798,6 +798,8 @@ JsonTokenSeek(JsonParserState * state)
if (!fgets(state->token + 1, 4, state->stream))
{
state->tokenType = TOKEN_EOF;
Free(state->token);
state->token = NULL;
return;
}
@ -809,12 +811,16 @@ JsonTokenSeek(JsonParserState * state)
else
{
state->tokenType = TOKEN_UNKNOWN;
Free(state->token);
state->token = NULL;
}
break;
case 'f':
if (!fgets(state->token + 1, 5, state->stream))
{
state->tokenType = TOKEN_EOF;
Free(state->token);
state->token = NULL;
return;
}
@ -826,12 +832,16 @@ JsonTokenSeek(JsonParserState * state)
else
{
state->tokenType = TOKEN_UNKNOWN;
Free(state->token);
state->token = NULL;
}
break;
case 'n':
if (!fgets(state->token + 1, 4, state->stream))
{
state->tokenType = TOKEN_EOF;
Free(state->token);
state->token = NULL;
return;
}
@ -842,10 +852,14 @@ JsonTokenSeek(JsonParserState * state)
else
{
state->tokenType = TOKEN_UNKNOWN;
Free(state->token);
state->token = NULL;
}
break;
default:
state->tokenType = TOKEN_UNKNOWN;
Free(state->token);
state->token = NULL;
break;
}
}