1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-05-04 15:06:03 +02:00

Clean up iterators, type contexts, and recursion level on errors

This commit is contained in:
JustAnotherArchivist 2022-02-14 03:24:55 +00:00 committed by Brénainn Woodsend
parent 4bd21e2483
commit 7f269a4818

View File

@ -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;
}
@ -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 ++;
@ -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 ++;