Can objects unwind before they are created on the stack?

We have been debugging a strange case for several days and have isolated the error somewhat, but it still makes no sense. Maybe someone here can let me know what is going on.

The problem is an access violation that occurs in a piece of code.

Basically we have something like this:

void aclass::somefunc() {
  try {
    erroneous_member_function(*someptr);
  } 
  catch (AnException) {
  }
}

void aclass::erroneous_member_function(const SomeObject& ref) {
  // { //<--scope here error goes away
  LargeObject obj = Singleton()->Object.someLargeObj; //<-remove this error goes away

  //DummyDestruct dummy1//<-- this is not destroyed before the unreachable

  throw AnException();

  // } //<--end scope here error goes away 

  UnreachableClass unreachable; //<- remove this, and the error goes away

  DummyDestruct dummy2; //<- destructor of this object is called! 
}

While in the debugger, it seems to destroy the UnreachableClass, and when I insert the DummyDestruct object, it does not crash until the strange destructor is called. So it doesn't seem like the destruction of the LargeObject is going wrong.

All this is in the middle of the production code, and it is very difficult to single out a small example.

: - , , ? , ( Embarcadero RAD), , .

- , ?

Update:

DummyDestruct throw . ( ).

+3
5

, , , , - /. ( , , ).

+1

- , - .. , , , . , , , , , . LargeObject ? ref? , somePtr SomeObject. Singleton() ? , . .

+1

:

- . , , , . , , , , !

, , . (, ) , , , , .

+1

, ...

, borland - ? , - STL? winsock2 ?

, borland 6 (2002) winsock - , , , std::string, , , .

0

, . , , , (STL) (.. , , "" , ). (GNU) , ( , , , ), 0, . , -, . ( , , 32- , , - , , , .)

0
source

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


All Articles