Skip to content

Commit

Permalink
Clean up iterators, type contexts, and recursion level on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAnotherArchivist authored and bwoodsend committed Feb 16, 2022
1 parent 4bd21e2 commit 7f269a4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ultrajsonenc.c
Expand Up @@ -659,8 +659,10 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
/*
There should already be an exception at the Python level.
This however sets the errorMsg so recursion on arrays and objects stops.
endTypeContext must not be called here as beginTypeContext already cleans up in the INVALID case.
*/
SetError (obj, enc, "Invalid type");
enc->level--;
return;
}

Expand Down Expand Up @@ -688,6 +690,9 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
encode (iterObj, enc, NULL, 0);
if (enc->errorMsg)
{
enc->iterEnd(obj, &tc);
enc->endTypeContext(obj, &tc);
enc->level--;
return;
}
count ++;
Expand Down Expand Up @@ -736,6 +741,9 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
encode (iterObj, enc, objName, szlen);
if (enc->errorMsg)
{
enc->iterEnd(obj, &tc);
enc->endTypeContext(obj, &tc);
enc->level--;
return;
}
count ++;
Expand Down

0 comments on commit 7f269a4

Please sign in to comment.