Commit eeda59a1 authored by snuverink_j's avatar snuverink_j

fix memory errors in unit tests as reported by valgrind: initialise array,...

fix memory errors in unit tests as reported by valgrind: initialise array, check for container end, array deletion
parent a299a45f
...@@ -714,7 +714,7 @@ LField<T,Dim>::allocateStorage(int newsize) ...@@ -714,7 +714,7 @@ LField<T,Dim>::allocateStorage(int newsize)
// Allocate the storage, creating some extra to account for offset, and // Allocate the storage, creating some extra to account for offset, and
// then add in the offset. // then add in the offset.
P = new T[newsize + extra]; P = new T[newsize + extra]();
P += extra; P += extra;
ADDIPPLSTAT(incLFieldBytes, (newsize+extra)*sizeof(T)); ADDIPPLSTAT(incLFieldBytes, (newsize+extra)*sizeof(T));
......
...@@ -127,7 +127,11 @@ public: ...@@ -127,7 +127,11 @@ public:
MyDomain(&(const_cast<S&>(s))), MyDomain(&(const_cast<S&>(s))),
CurrentLField(ldf), CurrentLField(ldf),
MyBrackets(B) { MyBrackets(B) {
LFPtr = (*CurrentLField).second.get(); if (CurrentLField != getBareField().end_if()) {
LFPtr = (*CurrentLField).second.get();
} else {
LFPtr = nullptr;
}
} }
// Default constructor // Default constructor
...@@ -156,9 +160,15 @@ public: ...@@ -156,9 +160,15 @@ public:
// Go to the next LField. // Go to the next LField.
typename BareField<T,Dim>::iterator_if nextLField() { typename BareField<T,Dim>::iterator_if nextLField() {
++CurrentLField; if (CurrentLField != getBareField().end_if()) {
LFPtr = (*CurrentLField).second.get(); ++CurrentLField;
return CurrentLField; }
if (CurrentLField != getBareField().end_if()) {
LFPtr = (*CurrentLField).second.get();
} else {
LFPtr = nullptr;
}
return CurrentLField;
} }
// Return the LField pointed to by LFPtr // Return the LField pointed to by LFPtr
......
...@@ -148,7 +148,7 @@ TEST_F(NDGridTest, CoordVectorTest) { // and newCoordArray ...@@ -148,7 +148,7 @@ TEST_F(NDGridTest, CoordVectorTest) { // and newCoordArray
EXPECT_NEAR(coords_v[j], gridCoordinates[i][j], 1e-12); EXPECT_NEAR(coords_v[j], gridCoordinates[i][j], 1e-12);
EXPECT_NEAR(coords_a[j], gridCoordinates[i][j], 1e-12); EXPECT_NEAR(coords_a[j], gridCoordinates[i][j], 1e-12);
} }
delete coords_a; delete[] coords_a;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment