@@ -107,6 +107,7 @@ typedef struct __TypeContext {
107
107
JSINT64 longValue ;
108
108
109
109
const char * cStr ;
110
+ int freeCStr ;
110
111
NpyArrContext * npyarr ;
111
112
PdBlockContext * pdblock ;
112
113
int transpose ;
@@ -162,6 +163,7 @@ static TypeContext *createTypeContext(void) {
162
163
pc -> longValue = 0 ;
163
164
pc -> doubleValue = 0.0 ;
164
165
pc -> cStr = NULL ;
166
+ pc -> freeCStr = 0 ;
165
167
pc -> npyarr = NULL ;
166
168
pc -> pdblock = NULL ;
167
169
pc -> rowLabels = NULL ;
@@ -327,13 +329,15 @@ static const char *NpyDateTimeToIsoCallback(JSOBJ Py_UNUSED(unused),
327
329
NPY_DATETIMEUNIT base = ((PyObjectEncoder * )tc -> encoder )-> datetimeUnit ;
328
330
NPY_DATETIMEUNIT valueUnit = ((PyObjectEncoder * )tc -> encoder )-> valueUnit ;
329
331
GET_TC (tc )-> cStr = int64ToIso (GET_TC (tc )-> longValue , valueUnit , base , len );
332
+ GET_TC (tc )-> freeCStr = 1 ;
330
333
return GET_TC (tc )-> cStr ;
331
334
}
332
335
333
336
/* JSON callback. returns a char* and mutates the pointer to *len */
334
337
static const char * NpyTimeDeltaToIsoCallback (JSOBJ Py_UNUSED (unused ),
335
338
JSONTypeContext * tc , size_t * len ) {
336
339
GET_TC (tc )-> cStr = int64ToIsoDuration (GET_TC (tc )-> longValue , len );
340
+ GET_TC (tc )-> freeCStr = 1 ;
337
341
return GET_TC (tc )-> cStr ;
338
342
}
339
343
@@ -347,7 +351,9 @@ static const char *PyDateTimeToIsoCallback(JSOBJ obj, JSONTypeContext *tc,
347
351
}
348
352
349
353
NPY_DATETIMEUNIT base = ((PyObjectEncoder * )tc -> encoder )-> datetimeUnit ;
350
- return PyDateTimeToIso (obj , base , len );
354
+ GET_TC (tc )-> cStr = PyDateTimeToIso (obj , base , len );
355
+ GET_TC (tc )-> freeCStr = 1 ;
356
+ return GET_TC (tc )-> cStr ;
351
357
}
352
358
353
359
static const char * PyTimeToJSON (JSOBJ _obj , JSONTypeContext * tc ,
@@ -1880,6 +1886,9 @@ static void Object_endTypeContext(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
1880
1886
GET_TC (tc )-> rowLabels = NULL ;
1881
1887
NpyArr_freeLabels (GET_TC (tc )-> columnLabels , GET_TC (tc )-> columnLabelsLen );
1882
1888
GET_TC (tc )-> columnLabels = NULL ;
1889
+ if (GET_TC (tc )-> freeCStr ) {
1890
+ PyObject_Free ((void * )GET_TC (tc )-> cStr );
1891
+ }
1883
1892
GET_TC (tc )-> cStr = NULL ;
1884
1893
PyObject_Free (tc -> prv );
1885
1894
tc -> prv = NULL ;
0 commit comments