Std :: list delete delete call on pointer?

I ran valgrind into my program due to segfault, I can not understand. A problem was found here ...

Address 0x75c7670 is 0 bytes inside a block of size 12 free'd
  at 0x4024851: operator delete(void*) (vg_replace_malloc.c:387)
  by 0x805F6D8: std::list<Object*, std::allocator<Object*>::remove(O
  bject* const&) (new_allocator.h:95)

Deletion occurs in this method ...

void ObjectManager::AdjustGridCoord( int x, int y, Object* const obj ) {
  // GetTileX and GetTileY guaranteed to be valid indices
  int newX = ObjectAttorney::GetTileX( obj );
  int newY = ObjectAttorney::GetTileY( obj );
  if ( x != newX || y != newY  ) {
    m_objGrid[x][y].remove( obj );
    m_objGrid[newX][newY].push_back( obj );
  }
} 

I did not think that removing a pointer from a list would trigger on it delete. What looks suspicious here? If you need more information, let me know.

PS Previously, when debugging, I noticed that the problem arose because GetTileX and GetTileY were not valid indices, and would return funny digits, such as 13775864. I think this is due to the problem delete, although deleting or push_back causes a problem.

Edit: Here is another piece of code

for ( unsigned int x = 0; x < m_objGrid.size(); ++x ) {
  for ( unsigned int y = 0; y < m_objGrid[x].size(); ++y ) {
    for ( ListItr obj = m_objGrid[x][y].begin(); obj != m_objGrid[x][y].end(); ++obj ) {
      ObjectAttorney::UpdateAI( *obj );
      AdjustGridCoord( x, y, *obj );
    }
  }
}

Could not configure GridCoord to invalidate the iterator?

+3
2

, , , .

( , obj , , ), :

m_objGrid[x][y].remove( obj );

obj, obj . valgrind, , , , obj. , obj . , , , , - :

++obj

obj - , , AdjustGridCoord. , , , valgrind.

:

  • , , AdjustGridCoord
  • , - , " ", .

2 std::vector<std::pair<unsigned int, unsigned int> >, , AdjustGridCoord on, , .

+2

12 free'd node, . , std::list::remove() delete , delete d node.

, () .

+1

Source: https://habr.com/ru/post/1757241/


All Articles