Skip to content

Commit b524c24

Browse files
committed
Merge branch 'fix/memoryLeaks' into develop
Fix memory leaks detected in OpDiLib tests.
2 parents 3d8f4ab + 4aed42f commit b524c24

4 files changed

Lines changed: 17 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
}

include/opdi/misc/tapePool.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace opdi {
5151
}
5252

5353
void finalize() {
54+
this->clear();
5455
omp_destroy_lock(&this->lock);
5556
}
5657

tests/tests/TestExternalFunctionGlobal.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ struct TestExternalFunctionGlobal : public TestBase<4, 1, 3, TestExternalFunctio
112112
for (int i = start; i < end; ++i) {
113113
jobResults[i] = cos(exp(intermediate[i]));
114114
}
115+
116+
OPDI_MASTER()
117+
{
118+
delete eh;
119+
}
120+
OPDI_END_MASTER
115121
}
116122
OPDI_END_PARALLEL
117123

@@ -120,5 +126,6 @@ struct TestExternalFunctionGlobal : public TestBase<4, 1, 3, TestExternalFunctio
120126
}
121127

122128
delete [] jobResults;
129+
delete [] intermediate;
123130
}
124131
};

tests/tests/TestExternalFunctionLocal.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct TestExternalFunctionLocal : public TestBase<4, 1, 3, TestExternalFunction
8383
for (int i = start; i < end; ++i) {
8484
jobResults[i] = cos(exp(intermediate[i]));
8585
}
86+
87+
delete eh;
8688
}
8789
OPDI_END_PARALLEL
8890

@@ -91,5 +93,6 @@ struct TestExternalFunctionLocal : public TestBase<4, 1, 3, TestExternalFunction
9193
}
9294

9395
delete [] jobResults;
96+
delete [] intermediate;
9497
}
9598
};

0 commit comments

Comments
 (0)