Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__vftptr is NULL

We received crash dump from customer site. I see that in one of the structures o nstack __vfptr is NUL.

Does it always point to problematic condition (memeory overrun, deleting object twice...) or is there case where this pointer can be null.

like image 364
Boris Avatar asked Nov 29 '22 07:11

Boris


2 Answers

Are you using memset() anywhere on instances of your classes?

I've seen this problem before and the cause was code like

class C : SomeClassWithVirtualFunctions
{
public:
  C()
  {
    memset( this, 0, sizeof ( C ) ) ; // BAD!! sets _vfptr to 0 too
  }
}

cppcheck is neat

like image 74
bobobobo Avatar answered Dec 01 '22 21:12

bobobobo


You may be seeing a partially destroyed object on the stack. The compiler may mark part of an object as destroyed by clearing the virtual function table pointer, so that it can correctly implement destructors of classes with "diamond" inheritance (multiple inheritance of classes that have a common, virtual base class) If the program crashes during the destruction of the object, you'll see the partially destroyed object in the dump.

Older MSVC compilers did not correctly implement destructors for classes with diamond inheritance. Any time you tried to destroy one, the program would crash. I'm not sure if this is still the case.

like image 24
Nat Avatar answered Dec 01 '22 21:12

Nat