Skip to content

Commit 57bdad9

Browse files
committed
Fix dangling pointer in SGSelector
1 parent 2cd4cab commit 57bdad9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

PWGUD/Core/SGSelector.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
#include "Framework/Logger.h"
2929

3030
#include <cmath>
31+
#include <memory>
3132

3233
template <typename BC>
3334
struct SelectionResult {
3435
int value; // The original integer return value
35-
const BC* bc; // Pointer to the BC object
36+
std::shared_ptr<BC> bc; // Pointer to the BC object
3637
};
3738

3839
namespace o2::aod::sgselector
@@ -66,9 +67,9 @@ class SGSelector
6667
// LOGF(info, "Collision %f", collision.collisionTime());
6768
// LOGF(info, "Number of close BCs: %i", bcRange.size());
6869
SelectionResult<BC> result;
69-
result.bc = &oldbc;
7070
if (collision.numContrib() < diffCuts.minNTracks() || collision.numContrib() > diffCuts.maxNTracks()) {
7171
result.value = o2::aod::sgselector::TrkOutOfRange; // 4
72+
result.bc = std::make_shared<BC>(oldbc);
7273
return result;
7374
}
7475
auto newbc = oldbc;
@@ -97,6 +98,7 @@ class SGSelector
9798
} // end of loop over bc range
9899
if (!gA && !gC) {
99100
result.value = o2::aod::sgselector::NoUpc; // gap = 3
101+
result.bc = std::make_shared<BC>(oldbc);
100102
return result;
101103
}
102104
if (gA && gC) { // loop once again for so-called DG events to get the most active FT0 BC
@@ -120,9 +122,8 @@ class SGSelector
120122
}
121123
newbc = newdgabc;
122124
}
123-
result.bc = &newbc;
124125
// LOGF(info, "Old BC: %i, New BC: %i",oldbc.globalBC(), newbc.globalBC());
125-
result.bc = &newbc;
126+
result.bc = std::make_shared<BC>(newbc);
126127
// result.value = gA && gC ? 2 : (gA ? 0 : 1);
127128
result.value = gA && gC ? o2::aod::sgselector::DoubleGap : (gA ? o2::aod::sgselector::SingleGapA : o2::aod::sgselector::SingleGapC);
128129
return result;

0 commit comments

Comments
 (0)