Gate icon indicating copy to clipboard operation
Gate copied to clipboard

Deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector and the Segfaults

Open Supernabla opened this issue 7 years ago • 5 comments

Deleting a G4MultiFunctionalDetector invokes the deletion of the registered primitives. Consequently, the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector invokes the deletion of Gate actors. There are two scenarios in which GateMultiSensitiveDetector::pMultiFunctionalDetector is deleted:

  1. delete pMultiFunctionalDetector is called in GateMultiSensitiveDetector::~GateMultiSensitiveDetector()
  2. GateMultiSensitiveDetector::pMultiFunctionalDetector is registered to the G4SDManager which takes the ownership.

People have been commenting in and out these cases in there commits, e.g. bda725bdccd9ade5d12f343c70464b3de241471f, because they figured it causes segfaults.

The deeper problem is the following: the singleton GateActorManager also claims ownership of all Gate actors, implementing their deletion in GateActorManager::~GateActorManager(). That causes a double free, if GateMultiSensitiveDetector::pMultiFunctionalDetector is deleted, too.

Supernabla avatar Nov 20 '17 11:11 Supernabla

You're right sorry ... What's the solution in your opinion ? Remove the loop that delete all actor in GateActorManager::~GateActorManager() ?

dsarrut avatar Nov 20 '17 12:11 dsarrut

First of all: thanks for the quick reply and thanks for the work you put into Gate.

Yeah, what you suggest is the provisional fix I was thinking of: Allow the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector and remove the loop in GateActorManager::~GateActorManager().

On the long term, the GateVActor <--> GateActorManager <--> GateMultiSensitiveDetector interfaces might need some more invasive refactoring.

Supernabla avatar Nov 20 '17 12:11 Supernabla

ok, done 12dd4c4f4267d10cda6ee6bed70ac869c903b28e

dsarrut avatar Nov 20 '17 12:11 dsarrut

Maybe, I was too quick with my suggestion... @dsarrut I saw, that you encountered problems again (see 8a23dd500ea70ba226f7dc6d9af04611210b23be), so maybe this issue should be re-opened.

Two important points:

  • At the moment, no actors are deleted, neither by GateMultiSensitiveDetector::pMultiFunctionalDetector nor by the GateActorManager, right?

  • I also noticed, that because some actors don't need to be attached to a volume (e.g. simulation statistics actor), they never become owned by a GateMultiSensitiveDetector::pMultiFunctionalDetector. Hence, deleting GateMultiSensitiveDetector::pMultiFunctionalDetector cannot be the general delete mechanism for actors.

In general, though, how do you track down your segfaults to the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector?

Supernabla avatar Dec 04 '17 12:12 Supernabla

Not clear how the cleaning is currently performed. I should investigate ... Maybe a shared_ptr approach could help, but will require lot of changes. Not time for this right now.

In general, though, how do you track down your segfaults to the deletion of GateMultiSensitiveDetector::pMultiFunctionalDetector? I just look trace with gdb ...

dsarrut avatar Dec 05 '17 07:12 dsarrut