[C++-sig] Re: Reference leak in life_support.cpp

David Abrahams dave at boost-consulting.com
Tue Sep 16 18:22:57 CEST 2003


Raoul Gough <RaoulGough at yahoo.co.uk> writes:

> I've been checking for reference leaks using python_d, and I think
> I've found one using return_internal_reference where the return value
> is a null pointer (or even just void). This gets returned to Python as
> Py_None, and there is a special case in life_support.cpp to handle it:
>
>     if (nurse == Py_None)
>         return incref(nurse);
>
> In my testing, this leaks a reference to Py_None, since the counter
> already got incremented in the boost::python::detail::none() call that
> originally introduced the Py_None pointer. This shows up as an
> increasing total ref count using python_d when invoking the following
> function:
>
> IntWrapper const *foo (IntWrapper const &i) {
>   return 0;
> }
>
> via a Python extension module with
>
>   def ("foo", foo, return_internal_reference<>());
>
> e.g.
>
>>>> foo(IntWrapper(3))
> [8453 refs]
>>>> foo(IntWrapper(3))
> [8454 refs]
>>>> foo(IntWrapper(3))
> [8455 refs]
>>>> foo(IntWrapper(3))
> [8456 refs]
>>>> foo(IntWrapper(3))
> [8457 refs]
>>>> foo(IntWrapper(3))
> [8458 refs]
>
> [etc...]

OK, good catch.  Feel free to check in a patch.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list