Skip to content
Snippets Groups Projects
Commit 06779d24 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix memory leak in ptr vector and array

parent a81755d1
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -207,20 +207,18 @@ public: ...@@ -207,20 +207,18 @@ public:
   
template < class R > template < class R >
iterator set ( const_iterator pos, R && value ) { iterator set ( const_iterator pos, R && value ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) ); return set ( pos, ext::clone ( std::forward < R > ( value ) ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
template < class R >
iterator set ( const_iterator pos, T * value ) { iterator set ( const_iterator pos, T * value ) {
delete m_data.at ( std::distance ( cbegin ( ), pos ) );
m_data.at ( std::distance ( cbegin ( ), pos ) ) = value ; m_data.at ( std::distance ( cbegin ( ), pos ) ) = value ;
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
template < class R, class ... Args > template < class R, class ... Args >
iterator emplace_set ( const_iterator pos, Args && ... args ) { iterator emplace_set ( const_iterator pos, Args && ... args ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ; return set ( pos, new R ( std::forward < Args > ( args ) ... ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
void swap ( ptr_array & other ) { void swap ( ptr_array & other ) {
......
...@@ -236,20 +236,18 @@ public: ...@@ -236,20 +236,18 @@ public:
   
template < class R > template < class R >
iterator set ( const_iterator pos, R && value ) { iterator set ( const_iterator pos, R && value ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) ); return set ( pos, ext::clone ( std::forward < R > ( value ) ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
template < class R >
iterator set ( const_iterator pos, T * value ) { iterator set ( const_iterator pos, T * value ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = value ; delete m_data.at ( std::distance ( cbegin ( ), pos ) );
m_data.at ( std::distance ( cbegin ( ), pos ) ) = value;
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
template < class R, class ... Args > template < class R, class ... Args >
iterator emplace_set ( const_iterator pos, Args && ... args ) { iterator emplace_set ( const_iterator pos, Args && ... args ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ; return set ( pos, new R ( std::forward < R > ( args ) ... ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
} }
   
template < class R > template < class R >
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment