Search code examples
c++pointersconstructorreverse-engineeringdereference

Dereferencing **this and setting *this to zero?


**this is getting dereferenced then it's value set to zero. Can someone explain what is happening here? One of these functions is constructor of some struct, I'm wondering which.

void **__thiscall PossiblyCtor1(void **this)
{
  void **ret;
  ret = this;
  *this = 0; // <- HERE
  PossiblyCtor2(this);
  return ret;
}

It was called in middle of some other function after malloc:

--- unimportant code ---

v43 = (void **)Allocate(4u, v46, v47);
if ( v43 )
  v44 = PossiblyCtor1(v43); // <- CALL
else
  v44 = 0;

--- unimportant code ---

Forgive me stupid names, but this is reverse engineered code from IDA.


Solution

  • [Solved] It is setting NULL as "value" of already heap allocated pointer (thanks Mooing Duck for help), then sending that NULL ptr as "this" to the constructor of some object.

    PossiblyCtor1 is an actual constructor.