Skip to content

Commit 9285f77

Browse files
committed
Fix memory leaks in OPDI_SINGLE* macros.
1 parent 5ea721b commit 9285f77

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

include/opdi/backend/macro/macros.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,17 @@
7979
#define OPDI_SINGLE_NOWAIT(...) \
8080
{ \
8181
bool constexpr opdiInternalBarrierIndicator = false; \
82-
void* opdiInternalTapePosition = opdi::tool->allocPosition(); \
83-
opdi::tool->getTapePosition(opdi::tool->getThreadLocalTape(), opdiInternalTapePosition); \
82+
void* opdiInternalTapePosition1 = opdi::tool->allocPosition(); \
83+
void* opdiInternalTapePosition2 = opdi::tool->allocPosition(); /* for consistency with the end macro */ \
84+
opdi::tool->getTapePosition(opdi::tool->getThreadLocalTape(), opdiInternalTapePosition1); \
8485
opdi::logic->onSyncRegion(opdi::LogicInterface::SyncRegionKind::BarrierImplementation, \
8586
opdi::LogicInterface::ScopeEndpoint::Begin); \
8687
opdi::ImplicitBarrierTools::beginRegionWithImplicitBarrier(); \
8788
{ \
8889
opdi::SingleProbe localSingleProbe; \
8990
OPDI_PRAGMA(omp single nowait __VA_ARGS__) \
9091
{ \
91-
opdi::tool->reset(opdi::tool->getThreadLocalTape(), opdiInternalTapePosition);
92+
opdi::tool->reset(opdi::tool->getThreadLocalTape(), opdiInternalTapePosition1);
9293

9394
#define OPDI_END_SINGLE \
9495
opdi::logic->onSyncRegion(opdi::LogicInterface::SyncRegionKind::BarrierImplementation, \
@@ -97,6 +98,8 @@
9798
opdi::logic->onSyncRegion(opdi::LogicInterface::SyncRegionKind::BarrierImplementation, \
9899
opdi::LogicInterface::ScopeEndpoint::End); \
99100
} \
101+
opdi::tool->freePosition(opdiInternalTapePosition1); \
102+
opdi::tool->freePosition(opdiInternalTapePosition2); \
100103
opdi::ImplicitBarrierTools::implicitBarrierStack.top() = opdiInternalBarrierIndicator; \
101104
opdi::ImplicitBarrierTools::endRegionWithImplicitBarrier(); \
102105
}

0 commit comments

Comments
 (0)