Skip to content

Commit

Permalink
Fix object reference leak from delegation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Aug 12, 2015
1 parent 78f4586 commit 7ea20bd
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions traits/ctraits.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ _has_traits_trait ( has_traits_object * obj, PyObject * args ) {
PyObject * name;
PyObject * daname;
PyObject * daname2;
PyObject * dict;
PyObject * dict;
int i, instance;

/* Parse arguments, which specify the trait name and whether or not an
Expand All @@ -1147,16 +1147,26 @@ _has_traits_trait ( has_traits_object * obj, PyObject * args ) {
}

dict = delegate->obj_dict;
if ( ((dict == NULL) ||
((temp_delegate = (has_traits_object *) PyDict_GetItem( dict,
trait->delegate_name )) == NULL)) &&
((temp_delegate = (has_traits_object *) has_traits_getattro(
delegate, trait->delegate_name )) == NULL) )
break;

temp_delegate = NULL;
if (dict != NULL) {
temp_delegate = (has_traits_object *) PyDict_GetItem(
dict, trait->delegate_name );
/* PyDict_GetItem returns a borrowed reference,
so we need to INCREF. */
Py_XINCREF( temp_delegate );
}
if (temp_delegate == NULL) {
/* has_traits_getattro returns a new reference,
so no need to INCREF. */
temp_delegate = (has_traits_object *) has_traits_getattro(
delegate, trait->delegate_name );
}
if (temp_delegate == NULL) {
break;
}
Py_DECREF( delegate );
delegate = temp_delegate;
Py_INCREF( delegate );

if ( !PyHasTraits_Check( delegate ) ) {
bad_delegate_error2( obj, name );
Expand Down

0 comments on commit 7ea20bd

Please sign in to comment.