valgrind confused by std::allocator calls to operator new(0)

Michael Veksler VEKSLER@il.ibm.com
Tue Feb 22 09:19:00 GMT 2005





On gcc-3.4.3 and 4.0 new_allocator<T>::allocate(0) will call
operator new(0). Additionally, in gcc-3.4.3 std::allocator is an alias
to new_allocator. As a result, operator new(0) will be called simply
by using std::vector in gcc-3.4.3.

There are 2 issues with this:
1. Potential efficiency problem.
2. It confuses valgrind (I have created 99923 KDE PR.).

Consider something like:
  static vector<int> empty;
  static vector<int> *p= new vector<int>(empty); //calls operator new(0);

Valgrind erroneously reports p->_M_impl->_M_start as lost.
It should have reported it as "still reachable".

It may be viewed as a low priority regression. In gcc-3.2 std::allocator
does not behave this way.

Is it possible/reasonable to change new_allocator::allocate such that
it returns NULL when __n ==0 ? Should I open a PR against libstdc++?




More information about the Libstdc++ mailing list