Skip to content

Commit b0d1967

Browse files
Fix memory leak in scoring (apt-sim#315)
Fixes a memory leak caused by the instantiation of vectors while reconstructing tracks from GPU data, which were never deallocated.
1 parent 5ea9d08 commit b0d1967

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/AdePTGeant4Integration.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,11 @@ void AdePTGeant4Integration::FillG4NavigationHistory(vecgeom::NavigationState aN
353353
void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4TouchableHandle &aPreG4TouchableHandle,
354354
G4TouchableHandle &aPostG4TouchableHandle)
355355
{
356-
const G4ThreeVector *aPostStepPointMomentumDirection =
357-
new G4ThreeVector(aGPUHit->fPostStepPoint.fMomentumDirection.x(), aGPUHit->fPostStepPoint.fMomentumDirection.y(),
356+
const G4ThreeVector aPostStepPointMomentumDirection(aGPUHit->fPostStepPoint.fMomentumDirection.x(), aGPUHit->fPostStepPoint.fMomentumDirection.y(),
358357
aGPUHit->fPostStepPoint.fMomentumDirection.z());
359-
const G4ThreeVector *aPostStepPointPolarization =
360-
new G4ThreeVector(aGPUHit->fPostStepPoint.fPolarization.x(), aGPUHit->fPostStepPoint.fPolarization.y(),
358+
const G4ThreeVector aPostStepPointPolarization(aGPUHit->fPostStepPoint.fPolarization.x(), aGPUHit->fPostStepPoint.fPolarization.y(),
361359
aGPUHit->fPostStepPoint.fPolarization.z());
362-
const G4ThreeVector *aPostStepPointPosition =
363-
new G4ThreeVector(aGPUHit->fPostStepPoint.fPosition.x(), aGPUHit->fPostStepPoint.fPosition.y(),
360+
const G4ThreeVector aPostStepPointPosition(aGPUHit->fPostStepPoint.fPosition.x(), aGPUHit->fPostStepPoint.fPosition.y(),
364361
aGPUHit->fPostStepPoint.fPosition.z());
365362

366363
// G4Step
@@ -377,17 +374,17 @@ void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4Touc
377374
G4Track *aTrack = aG4Step->GetTrack();
378375
aTrack->SetTrackID(aGPUHit->fParentID); // Missing data
379376
aTrack->SetParentID(aGPUHit->fParentID); // ID of the initial particle that entered AdePT
380-
aTrack->SetPosition(*aPostStepPointPosition); // Real data
377+
aTrack->SetPosition(aPostStepPointPosition); // Real data
381378
// aTrack->SetGlobalTime(0); // Missing data
382379
// aTrack->SetLocalTime(0); // Missing data
383380
// aTrack->SetProperTime(0); // Missing data
384381
// aTrack->SetTouchableHandle(aTrackTouchableHistory); // Missing data
385382
// aTrack->SetNextTouchableHandle(nullptr); // Missing data
386383
// aTrack->SetOriginTouchableHandle(nullptr); // Missing data
387384
// aTrack->SetKineticEnergy(aGPUHit->fPostStepPoint.fEKin); // Real data
388-
aTrack->SetMomentumDirection(*aPostStepPointMomentumDirection); // Real data
385+
aTrack->SetMomentumDirection(aPostStepPointMomentumDirection); // Real data
389386
// aTrack->SetVelocity(0); // Missing data
390-
aTrack->SetPolarization(*aPostStepPointPolarization); // Real data
387+
aTrack->SetPolarization(aPostStepPointPolarization); // Real data
391388
// aTrack->SetTrackStatus(G4TrackStatus::fAlive); // Missing data
392389
// aTrack->SetBelowThresholdFlag(false); // Missing data
393390
// aTrack->SetGoodForTrackingFlag(false); // Missing data
@@ -434,11 +431,11 @@ void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4Touc
434431

435432
// Post-Step Point
436433
G4StepPoint *aPostStepPoint = aG4Step->GetPostStepPoint();
437-
aPostStepPoint->SetPosition(*aPostStepPointPosition); // Real data
434+
aPostStepPoint->SetPosition(aPostStepPointPosition); // Real data
438435
// aPostStepPoint->SetLocalTime(0); // Missing data
439436
// aPostStepPoint->SetGlobalTime(0); // Missing data
440437
// aPostStepPoint->SetProperTime(0); // Missing data
441-
aPostStepPoint->SetMomentumDirection(*aPostStepPointMomentumDirection); // Real data
438+
aPostStepPoint->SetMomentumDirection(aPostStepPointMomentumDirection); // Real data
442439
aPostStepPoint->SetKineticEnergy(aGPUHit->fPostStepPoint.fEKin); // Real data
443440
// aPostStepPoint->SetVelocity(0); // Missing data
444441
if (fPostG4TouchableHistoryHandle->GetVolume()) { // protect against nullptr if postNavState is outside
@@ -450,7 +447,7 @@ void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4Touc
450447
}
451448
// aPostStepPoint->SetSensitiveDetector(nullptr); // Missing data
452449
// aPostStepPoint->SetSafety(0); // Missing data
453-
aPostStepPoint->SetPolarization(*aPostStepPointPolarization); // Real data
450+
aPostStepPoint->SetPolarization(aPostStepPointPolarization); // Real data
454451
// aPostStepPoint->SetStepStatus(G4StepStatus::fUndefined); // Missing data
455452
// aPostStepPoint->SetProcessDefinedStep(nullptr); // Missing data
456453
// aPostStepPoint->SetMass(0); // Missing data

0 commit comments

Comments
 (0)