Re: [Dbus-cxx-devel] DBus::Error Double Free
Status: Beta
Brought to you by:
rvinyard
From: Rick L. V. Jr. <rvi...@cs...> - 2010-01-22 20:02:53
|
Hello, I went ahead and reworked the error methods. The problem with testing whether the error is set is that it may allocate resources, such as the error string, but have the error code set to off. Thus it would pose a memory leak. Instead what is really needed is reference counting. Instead of adding reference counting I went ahead and make the errors use smart pointers like the rest of the library, and as a result the errors are now reference counted and shouldn't have any issues. I combined this with several patches that have been sent in the last month and pushed out 0.6.0. Tyler Conant wrote: > I was calling a proxy method which didn't exist. The Exception which was > thrown was causing a double free error on the destructor. The Dbus::Error > was getting copied as it was passed down to the catch. I added a copy > constructor which copies the DBusError name and message. It also checks to > see if the error was already freed in the desctructor. > > > diff -ru dbus-cxx-0.5.0.org/dbus-cxx/error.cpp > dbus-cxx-0.5.0/dbus-cxx/error.cpp > --- dbus-cxx-0.5.0.org/dbus-cxx/error.cpp 2009-09-29 13:26:15.000000000 > -0700 > +++ dbus-cxx-0.5.0/dbus-cxx/error.cpp 2010-01-18 08:20:46.000000000 > -0800 > @@ -27,6 +27,14 @@ > dbus_error_init( &m_cobj ); > } > > + Error::Error( const Error & rhs ) > + { > + dbus_error_init( &m_cobj ); > + dbus_bool_t retVal = dbus_error_is_set(&m_cobj); > + if(retVal == TRUE ) > + dbus_set_error( &m_cobj, rhs.m_cobj.name, rhs.m_cobj.message ); > + } > + > Error::Error( DBusError * cobj ) > { > dbus_error_init( &m_cobj ); > @@ -61,7 +69,9 @@ > > Error::~Error( ) throw() > { > - dbus_error_free( &m_cobj ); > + dbus_bool_t retVal = dbus_error_is_set(&m_cobj); > + if(retVal == TRUE ) > + dbus_error_free( &m_cobj ); > } > > const char* Error::name() const > diff -ru dbus-cxx-0.5.0.org/dbus-cxx/error.h > dbus-cxx-0.5.0/dbus-cxx/error.h > --- dbus-cxx-0.5.0.org/dbus-cxx/error.h 2009-05-05 15:17:50.000000000 > -0700 > +++ dbus-cxx-0.5.0/dbus-cxx/error.h 2010-01-15 14:47:32.000000000 -0800 > @@ -55,6 +55,8 @@ > > Error(); > > + Error( const Error & rhs ); > + > Error( DBusError* cobj ); > > Error( const char* name, const char* message=NULL ); > > > ------------------------------------------------------------------------------ > Throughout its 18-year history, RSA Conference consistently attracts the > world's best and brightest in the field, creating opportunities for > Conference > attendees to learn about information security's most important issues > through > interactions with peers, luminaries and emerging and established > companies. > http://p.sf.net/sfu/rsaconf-dev2dev_______________________________________________ > Dbus-cxx-devel mailing list > Dbu...@li... > https://lists.sourceforge.net/lists/listinfo/dbus-cxx-devel > |