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:
 
template < class R >
iterator set ( const_iterator pos, R && value ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
return set ( pos, ext::clone ( std::forward < R > ( value ) ) );
}
 
template < class R >
iterator set ( const_iterator pos, T * 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 ) );
}
 
template < class R, class ... Args >
iterator emplace_set ( const_iterator pos, Args && ... args ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ;
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
return set ( pos, new R ( std::forward < Args > ( args ) ... ) );
}
 
void swap ( ptr_array & other ) {
......
......@@ -236,20 +236,18 @@ public:
 
template < class R >
iterator set ( const_iterator pos, R && value ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) );
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
return set ( pos, ext::clone ( std::forward < R > ( value ) ) );
}
 
template < class R >
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 ) );
}
 
template < class R, class ... Args >
iterator emplace_set ( const_iterator pos, Args && ... args ) {
m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ;
return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) );
return set ( pos, new R ( std::forward < R > ( args ) ... ) );
}
 
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