Skip to content
This repository was archived by the owner on Mar 8, 2018. It is now read-only.

Commit 1f3221e

Browse files
author
R. Tyler Croy
committed
Merge pull request #36 from ericpeden/memory-leaks
memory leak fixes
2 parents 5209483 + a652ad0 commit 1f3221e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

encoder.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
142142
}
143143
}
144144
buffer[offset] = '\0';
145-
return yajl_gen_raw_string(handle, (const unsigned char *)(buffer), (unsigned int)(offset));
145+
status = yajl_gen_raw_string(handle, (const unsigned char *)(buffer), (unsigned int)(offset));
146+
free(buffer);
147+
return status;
146148
}
147149
#ifdef IS_PYTHON3
148150
if (PyBytes_Check(object)) {
@@ -238,6 +240,9 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
238240
}
239241

240242
status = ProcessObject(self, newKey);
243+
if (key != newKey) {
244+
Py_XDECREF(newKey);
245+
}
241246
if (status == yajl_gen_in_error_state) return status;
242247
if (status == yajl_max_depth_exceeded) goto exit;
243248

yajl.c

+1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ static PyObject *_internal_stream_dump(PyObject *object, PyObject *stream, unsig
339339
buffer = _internal_encode((_YajlEncoder *)encoder, object, config);
340340
PyObject_CallMethodObjArgs(stream, __write, buffer, NULL);
341341
Py_XDECREF(encoder);
342+
Py_XDECREF(buffer);
342343
return Py_True;
343344

344345
bad_type:

0 commit comments

Comments
 (0)