Menu

#11 Unsafe copy assignment operator in WSSession

closed
nobody
None
True
2015-09-10
2015-08-31
No

The destructor deletes the pointer members:

WSSession::~WSSession( )
{
    delete m_navigationService;
    delete m_objectService;
    delete m_repositoryService;
    delete m_versioningService;
}

but the assignment operator doesn't:

WSSession& WSSession::operator=( const WSSession& copy )
{
    if ( this != &copy )
    {
        BaseSession::operator=( copy );
        m_servicesUrls = copy.m_servicesUrls;
        m_navigationService = NULL;
        m_objectService = NULL;
        m_repositoryService = NULL;
        m_versioningService = NULL;
        m_responseFactory = copy.m_responseFactory;
    }

    return *this;
}

That means if the pointer members are non-null when it is assigned to then everything leaks.

Discussion

  • Cedric Bosdonnat

    Thanks for the report. I'll try to check all objects and fix that, though I can't say when

     
  • Jonathan Wakely

    Jonathan Wakely - 2015-09-01

    Here's a patch to delete the existing members before setting the pointers to null. This only offers the Basic Exception-safety Guarantee, because if assigning the base subobject or the m_serviceUrls or m_responseFactory members throws a bad_alloc exception then the object will be left in an inconsistent state (some members updated and some not) but it won't leak and won't leave any dangling pointers.

    This doesn't cause any test failures, but I don't think any of the tests actually use this assignment operator.

     

    Last edit: Jonathan Wakely 2015-09-01
  • Cedric Bosdonnat

    • status: open --> closed
    • Patch: False --> True
     
  • Cedric Bosdonnat

    pushed in master. Thanks for the patch

     

Log in to post a comment.