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