Skip to main content
added 356 characters in body
Source Link
AlexT
  • 263
  • 1
  • 6

There is small possibility to have memory leak here:

    _head = new Node;
    _tail = new Node;

consider if after successfull allocaiton of first Node you get std::bad_alloc on second Node

Class invariant is not preserved here:

    _size++;
    return iterator( p->_prev = p->_prev->_next = new Node( x, p->_prev, p ) );

Again there is small posibility of std::bad_alloc when you create new Node but you have already increased _size

By the way - I remember leading underscores are discouraged from usage in application code

There is small possibility to have memory leak here:

    _head = new Node;
    _tail = new Node;

consider if after successfull allocaiton of first Node you get std::bad_alloc on second Node

There is small possibility to have memory leak here:

    _head = new Node;
    _tail = new Node;

consider if after successfull allocaiton of first Node you get std::bad_alloc on second Node

Class invariant is not preserved here:

    _size++;
    return iterator( p->_prev = p->_prev->_next = new Node( x, p->_prev, p ) );

Again there is small posibility of std::bad_alloc when you create new Node but you have already increased _size

By the way - I remember leading underscores are discouraged from usage in application code

Source Link
AlexT
  • 263
  • 1
  • 6

There is small possibility to have memory leak here:

    _head = new Node;
    _tail = new Node;

consider if after successfull allocaiton of first Node you get std::bad_alloc on second Node