Browse files

Fixed leaking reference

  • Loading branch information...
1 parent 3245c54 commit ec94c93f95ff25cdb7ef8396fdbb00c50806ea32 Kevin Manley committed Jan 19, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 python/objToJSON.c
4 python/objToJSON.c
@@ -582,9 +582,11 @@ void Object_beginTypeContext (PyObject **obj, JSONTypeContext *tc)
- // NOTE: recursive call
+ // NOTE: recursive call to Object_beginTypeContext
+ Py_DECREF(*obj);
*obj = jsonDefaultResult;
Object_beginTypeContext(obj, tc);

1 comment on commit ec94c93


Thanks for the pull request.

I think the Py_DECREF(*obj) line will cause us problems. As far as I see it we stand of at risk of actually deleting the object being encoded and possibly its entire sub structure.

Suppose the object we're decrefing is the root object which would have 1 or more references held to it. If the ref count is 1 and we decref it the refcount will hit 0 and the object and its sub objects will be deleted.

I played around with this myself using your old code and there's something fundamentally problematic with trying to retrofit this into the present encoder structures. Maybe we need some completely new thinking to make it work.

Please sign in to comment.