Skip to content

Commit

Permalink
Fix bytesObj not getting assigned and DECREFd, resulting in a memory …
Browse files Browse the repository at this point in the history
…leak
  • Loading branch information
JustAnotherArchivist committed May 30, 2022
1 parent 98321fa commit 59aa3bf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/objToJSON.c
Expand Up @@ -114,7 +114,7 @@ static void *PyStringToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, siz
return PyBytes_AsString(obj);
}

static char *PyUnicodeToUTF8Raw(JSOBJ _obj, size_t *_outLen, PyObject *bytesObj)
static char *PyUnicodeToUTF8Raw(JSOBJ _obj, size_t *_outLen, PyObject **pBytesObj)
{
/*
Converts the PyUnicode object to char* whose size is stored in _outLen.
Expand All @@ -134,7 +134,7 @@ static char *PyUnicodeToUTF8Raw(JSOBJ _obj, size_t *_outLen, PyObject *bytesObj)
}
#endif

bytesObj = PyUnicode_AsEncodedString (obj, NULL, "surrogatepass");
PyObject *bytesObj = *pBytesObj = PyUnicode_AsEncodedString (obj, NULL, "surrogatepass");
if (!bytesObj)
{
return NULL;
Expand All @@ -146,7 +146,7 @@ static char *PyUnicodeToUTF8Raw(JSOBJ _obj, size_t *_outLen, PyObject *bytesObj)

static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
return PyUnicodeToUTF8Raw(_obj, _outLen, GET_TC(tc)->newObj);
return PyUnicodeToUTF8Raw(_obj, _outLen, &(GET_TC(tc)->newObj));
}

static void *PyRawJSONToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
Expand Down

0 comments on commit 59aa3bf

Please sign in to comment.