Opened 15 years ago

Closed 15 years ago

#1714 closed Bugs (fixed)

crash due to new shared_from_this code

Reported by: Dave Abrahams Owned by: Frank Mori Hess
Milestone: Boost 1.36.0 Component: smart_ptr
Version: Boost Development Trunk Severity: Regression
Keywords: Cc: Peter Dimov

Description

The following crash is generated by

cd libs/python/test 
bjam andreas_beyer

backtrace:

>	andreas_beyer_ext.pyd!shared_ptr<const void>::operator=()  + 0xf bytes	C++

 	andreas_beyer_ext.pyd!sp_deleter_wrapper::set_deleter(const boost::shared_ptr<const void> & deleter={...})  Line 645	C++

 	andreas_beyer_ext.pyd!enable_shared_from_this<A>::_internal_accept_owner(boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> & owner={...})  Line 97 + 0x59 bytes	C++

 	andreas_beyer_ext.pyd!boost::detail::sp_enable_shared_from_this(boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> * ptr=0x0021f47c, const boost::enable_shared_from_this<A> * pe=0x00986a78)  Line 102	C++

 	andreas_beyer_ext.pyd!_internal_element_type>::shared_ptr(A * p=0x00986a78, boost::python::converter::shared_ptr_deleter d={...})  Line 192 + 0x15 bytes	C++

 	andreas_beyer_ext.pyd!shared_ptr_from_python<A>::construct(_object * const source=0x00a81f70, boost::python::converter::rvalue_from_python_stage1_data * data=0x0021f474)  Line 50 + 0x7 bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!boost::python::converter::rvalue_from_python_stage2(_object * source=0x00a81f70, boost::python::converter::rvalue_from_python_stage1_data & data={...}, const boost::python::converter::registration & converters={...})  Line 112 + 0x18 bytes	C++

 	andreas_beyer_ext.pyd!_internal_element_type> >::operator()()  Line 186 + 0x26 bytes	C++

 	andreas_beyer_ext.pyd!_internal_element_type> >::operator const boost::shared_ptr<A> &()  Line 138 + 0xa bytes	C++

 	andreas_beyer_ext.pyd!hold_python(boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> & x={...})  Line 40 + 0x74 bytes	C++

 	andreas_beyer_ext.pyd!get_b_a(boost::shared_ptr<B> b={...})  Line 45 + 0x19 bytes	C++

 	andreas_beyer_ext.pyd!boost::python::detail::invoke(const boost::python::to_python_value<boost::mpl::if_<boost::python::detail::copy_ctor_mutates_rhs<boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> >, boost::unwrap_reference<boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> >::type, boost::add_reference<boost::add_const<boost::unwrap_reference<boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> >::type>::type>::type>::type> & rc={...}, boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> * (boost::shared_ptr<boost::enable_shared_from_this<A>::_internal_element_type> *, boost::shared_ptr<B>)* & f=0x1000189d, boost::python::arg_from_python<boost::mpl::v_iter<boost::mpl::vector2<A::A_ptr, boost::shared_ptr<B> >::type, 1L>::type> & ac0={...})  Line 75 + 0x30 bytes	C++

 	andreas_beyer_ext.pyd!oost::mpl::and_<boost::mpl::not_<boost::is_same<const boost::python::detail::not_specified &, boost::mpl::_1> >, boost::detail::indirect_traits::is_reference_to_class<boost::mpl::_1>, boost::mpl::not_<boost::python::detail::is_reference_to_keywords<boost::mpl::_1> >, boost::mpl::true_, boost::mpl::true_>, boost::mpl::void_>::type>::result_type, boost::mpl::vector2<A::A_ptr, boost::shared_ptr<B> > >::operator()(_object * const args_=0x00ba0790, boost::python::detail::caller_arity<1U>::impl<A::A_ptr *(*)(A::A_ptr *, boost::shared_ptr<B>), boost::python::detail::tuple_extract_impl<false>::apply<boost::python::detail::def_helper<const char *, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::all_t, boost::mpl::lambda<boost::mpl::and_<boost::mpl::not_<boost::is_same<const boost::python::detail::not_specified &, boost::mpl::_1> >, boost::detail::indirect_traits::is_reference_to_class<boost::mpl::_1>, boost::mpl::not_<boost::python::detail::is_reference_to_keywords<boost::mpl::_1> >, boost::mpl::true_, boost::mpl::true_>, boost::mpl::void_>::type>::result_type, boost::mpl::vector2<A::A_ptr, boost::shared_ptr<B> > > * this=0x009869f4)  Line 218 + 0x5 bytes	C++

 	andreas_beyer_ext.pyd!st::mpl::and_<boost::mpl::not_<boost::is_same<const boost::python::detail::not_specified &, boost::mpl::_1> >, boost::detail::indirect_traits::is_reference_to_class<boost::mpl::_1>, boost::mpl::not_<boost::python::detail::is_reference_to_keywords<boost::mpl::_1> >, boost::mpl::true_, boost::mpl::true_>, boost::mpl::void_>::type>::result_type, boost::mpl::vector2<A::A_ptr, boost::shared_ptr<B> > > >::operator()(_object * const args=0x00ba0790, _object * const kw=0x00000000)  Line 38 + 0x1d bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!py_function::operator()(_object * args=0x00ba0790, _object * kw=0x00000000)  Line 143 + 0x32 bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!function::call(_object * args=0x00ba0790, _object * keywords=0x00000000)  Line 226 + 0x47 bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!bind_return::operator()()  Line 581 + 0x23 bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!objects::?%546a76fe::bind_return>::type, void>::invoke(boost::detail::function::function_buffer & function_obj_ptr={...})  Line 194	C++

 	boost_python-iw-mt-gd-1_35.dll! >::operator()()  Line 824 + 0x2 bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!boost::python::handle_exception_impl(boost::function0<void, std::allocator<boost::function_base> > f={...})  Line 25 + 0xa bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!boost::python::handle_exception(boost::python::objects::?%546a76fe::bind_return f={...})  Line 29 + 0x3a bytes	C++

 	boost_python-iw-mt-gd-1_35.dll!boost::python::objects::function_call(_object * const func=0x00986a28, _object * const args=0x00ba0790, _object * const kw=0x00000000)  Line 613 + 0x49 bytes	C++

 	python25.dll!1e0266dc() 	

 	[Frames below may be incorrect and/or missing, no symbols loaded for python25.dll]	

 	python25.dll!1e039e6d() 	

 	python25.dll!1e03ae12() 	

 	python25.dll!1e03cdca() 	

 	python25.dll!1e07090e() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e03dd42() 	

 	python25.dll!1e03dfab() 	

 	python25.dll!1e03c1ab() 	

 	python25.dll!1e0709f2() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e039bfc() 	

 	python25.dll!1e03ae02() 	

 	python25.dll!1e03cdca() 	

 	python25.dll!1e07090e() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e039bfc() 	

 	python25.dll!1e03ae02() 	

 	python25.dll!1e03cdca() 	

 	python25.dll!1e07090e() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e039bfc() 	

 	python25.dll!1e03ae02() 	

 	python25.dll!1e03cdca() 	

 	python25.dll!1e07090e() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e039bfc() 	

 	python25.dll!1e03ae02() 	

 	python25.dll!1e03c5c1() 	

 	python25.dll!1e03cdca() 	

 	python25.dll!1e07090e() 	

 	python25.dll!1e03dcdd() 	

 	python25.dll!1e0818ab() 	

 	python25.dll!1e03dd42() 	

 	python25.dll!1e0ab00a() 	

 	python25.dll!1e0abf86() 	

 	python25.dll!1e0ac65d() 	

 	msvcr71.dll!7c38a87e() 	

 	python25.dll!1e0acc6a() 	

 	python25.dll!1e08a396() 	

 	python.exe!1d0011a5() 	

 	kernel32.dll!7c816fd7() 	

Attachments (1)

enable_shared_from_this.patch (963 bytes ) - added by Dave Abrahams 15 years ago.
This appears to fix the bug but I have no idea if the logic is right.

Download all attachments as: .zip

Change History (4)

comment:1 by Peter Dimov, 15 years ago

Cc: Peter Dimov added

This is likely caused by the fact that _internal_accept_owner doesn't check whether _owned isn't already true. The following simpler test also crashes:

#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

struct X: public boost::enable_shared_from_this< X >
{
};

struct null_deleter
{
    void operator()( void const* ) const
    {
    }
};

int main()
{
    boost::shared_ptr<X> px( new X );
    boost::shared_ptr<X> px2( px.get(), null_deleter() );
}

by Dave Abrahams, 15 years ago

This appears to fix the bug but I have no idea if the logic is right.

comment:2 by Peter Dimov, 15 years ago

I checked in a fix: [43856]

comment:3 by Dave Abrahams, 15 years ago

Resolution: fixed
Status: newclosed

it works!

Note: See TracTickets for help on using tickets.