Skip to content

Commit b0839c4

Browse files
committed
Correction of a memory leak in reconstruct
1 parent 0c63ce3 commit b0839c4

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

include/compressedStack.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ template <class T, class D> class CompressedStack : public Stack<T, D> {
7474
void setSign(int component, Signature<T, D> sign = Signature<T, D>());
7575
void setLast(int component, int index, int lvl = -1);
7676
int getLast(int lvl, int component = 0);
77-
Signature<T, D> *getSign(int component, int lvl = 0);
77+
std::shared_ptr<Signature<T, D>> getSign(int component, int lvl = 0);
7878

7979
/* Push related */
8080
void pushExplicit(SPData<T, D> elt);
@@ -324,16 +324,14 @@ int CompressedStack<T, D>::getLast(int lvl, int component) {
324324
}
325325

326326
template <class T, class D>
327-
Signature<T, D> *CompressedStack<T, D>::getSign(int component, int lvl) {
328-
Signature<T, D> *sign;
327+
std::shared_ptr<Signature<T, D>> CompressedStack<T, D>::getSign(int component, int lvl) {
329328
if (lvl == 0) {
330-
sign = &mCompressed.back();
329+
return std::make_shared<Signature<T, D>>(mCompressed.back());
331330
} else if (component == 1) {
332-
sign = &mFirst.mPartial[lvl - 1].back();
331+
return std::make_shared<Signature<T, D>>(mFirst.mPartial[lvl - 1].back());
333332
} else {
334-
sign = &mSecond.mPartial[lvl - 1].back();
333+
return std::make_shared<Signature<T, D>>(mSecond.mPartial[lvl - 1].back());
335334
}
336-
return sign;
337335
}
338336

339337
/*==============================================================================
@@ -616,7 +614,7 @@ void CompressedStack<T, D>::compress(Block<T, D> block) {
616614
==============================================================================*/
617615
template <class T, class D>
618616
void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
619-
Signature<T, D> *sign = new Signature<T,D>();
617+
std::shared_ptr<Signature<T, D>> sign;
620618
int lvl;
621619
for (lvl = mDepth; lvl >= 0; lvl--) {
622620
if (lvl == 0) {

include/problem.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ template <class T, class D> void Problem<T, D>::run() {
223223
}
224224

225225
template <class T, class D> void Problem<T, D>::run(int limit) {
226-
int testIndex = mIndex;
226+
// int testIndex = mIndex;
227227
while (mInput.good() && mIndex < limit) {
228228
std::streampos position = mInput.tellg();
229229
(*mStack).setPosition(position);

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ void test(std::string filePath,int code2)
9898

9999
switch(code2) {
100100
case 0: {
101-
Instance testNS(filePath);
101+
Instance stack(filePath);
102102
// Test on normal stack
103-
testNS.run();
103+
stack.run();
104104
//testNS.println();
105105
break;
106106
}

0 commit comments

Comments
 (0)