Skip to content

Commit db8d797

Browse files
N-Dekkerdzenanz
authored andcommitted
BUG: Let MeshIOTestHelper AllocateBuffer return std::shared_ptr<void>
Let AllocateBuffer (from MeshIOTestHelper) return a `std::shared_ptr<void>`, instead of producing a void pointer, to ensure that it is deleted correctly, automatically. Aims to fix Valgrind errors, saying: > Mismatched free() / delete / delete [] As reported and discussed by Jon Haitz Legarreta Gorroño and Mihail Isakov at pull request #3459
1 parent 358f537 commit db8d797

File tree

7 files changed

+132
-173
lines changed

7 files changed

+132
-173
lines changed

Modules/IO/MeshBYU/test/itkBYUMeshIOTest.cxx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ itkBYUMeshIOTest(int argc, char * argv[])
4747
testStatus = TestBaseClassMethodsMeshIO<itk::BYUMeshIO>(byuMeshIOBaseTest);
4848

4949
// Test reading exceptions
50-
void * pointBuffer = nullptr;
51-
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->ReadPoints(pointBuffer));
52-
53-
void * cellBuffer = nullptr;
54-
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->ReadCells(cellBuffer));
50+
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->ReadPoints(nullptr));
51+
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->ReadCells(nullptr));
5552

5653
std::string inputFileName = argv[3];
5754
ITK_TEST_EXPECT_TRUE(!byuMeshIO->CanReadFile(inputFileName.c_str()));
@@ -98,16 +95,18 @@ itkBYUMeshIOTest(int argc, char * argv[])
9895
itk::SizeValueType pointBufferSize = 1000;
9996
itk::SizeValueType cellBufferSize = 1000;
10097

101-
AllocateBuffer(&pointBuffer, byuMeshIO->GetPointComponentType(), pointBufferSize);
102-
AllocateBuffer(&cellBuffer, byuMeshIO->GetCellComponentType(), cellBufferSize);
98+
const std::shared_ptr<void> pointBuffer =
99+
itk::MeshIOTestHelper::AllocateBuffer(byuMeshIO->GetPointComponentType(), pointBufferSize);
100+
const std::shared_ptr<void> cellBuffer =
101+
itk::MeshIOTestHelper::AllocateBuffer(byuMeshIO->GetCellComponentType(), cellBufferSize);
103102

104-
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->ReadPoints(pointBuffer));
103+
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->ReadPoints(pointBuffer.get()));
105104

106105
void * pointDataBuffer = nullptr;
107106
// Not used; empty method body; called for coverage purposes
108107
byuMeshIO->ReadPointData(pointDataBuffer);
109108

110-
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->ReadCells(cellBuffer));
109+
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->ReadCells(cellBuffer.get()));
111110

112111
void * cellDataBuffer = nullptr;
113112
// Not used; empty method body; called for coverage purposes
@@ -116,8 +115,8 @@ itkBYUMeshIOTest(int argc, char * argv[])
116115
// Test writing exceptions
117116
std::string outputFileName = "";
118117
byuMeshIO->SetFileName(outputFileName);
119-
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->WritePoints(pointBuffer));
120-
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->WriteCells(cellBuffer));
118+
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->WritePoints(pointBuffer.get()));
119+
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->WriteCells(cellBuffer.get()));
121120
ITK_TRY_EXPECT_EXCEPTION(byuMeshIO->WriteMeshInformation());
122121

123122
outputFileName = argv[4];
@@ -128,12 +127,12 @@ itkBYUMeshIOTest(int argc, char * argv[])
128127
byuMeshIO->SetFileName(outputFileName.c_str());
129128

130129
// Write the actual data
131-
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->WritePoints(pointBuffer));
130+
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->WritePoints(pointBuffer.get()));
132131

133132
// Not used; empty method body; called for coverage purposes
134133
byuMeshIO->WritePointData(pointDataBuffer);
135134

136-
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->WriteCells(cellBuffer));
135+
ITK_TRY_EXPECT_NO_EXCEPTION(byuMeshIO->WriteCells(cellBuffer.get()));
137136

138137
// Not used; empty method body; called for coverage purposes
139138
byuMeshIO->WriteCellData(cellDataBuffer);
@@ -174,9 +173,6 @@ itkBYUMeshIOTest(int argc, char * argv[])
174173
readWriteByuMeshIO->GetNumberOfCellPixelComponents());
175174

176175

177-
::operator delete(pointBuffer);
178-
::operator delete(cellBuffer);
179-
180176
std::cout << "Test finished." << std::endl;
181177
return testStatus;
182178
}

Modules/IO/MeshBase/include/itkMeshIOTestHelper.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,59 +375,59 @@ TestBaseClassMethodsMeshIO(typename TMeshIO::Pointer meshIO)
375375
return EXIT_SUCCESS;
376376
}
377377

378-
void
379-
AllocateBuffer(void ** data, itk::IOComponentEnum componentType, itk::SizeValueType bufferSize)
378+
namespace itk
379+
{
380+
namespace MeshIOTestHelper
380381
{
381-
void * buffer = nullptr;
382382

383+
template <typename T>
384+
std::shared_ptr<void>
385+
MakeSharedArray(const std::size_t bufferSize)
386+
{
387+
return std::shared_ptr<void>(new T[bufferSize], std::default_delete<T[]>());
388+
}
389+
390+
inline std::shared_ptr<void>
391+
AllocateBuffer(itk::IOComponentEnum componentType, itk::SizeValueType bufferSize)
392+
{
383393
switch (componentType)
384394
{
385395
case itk::IOComponentEnum::CHAR:
386-
buffer = new char[bufferSize];
387-
break;
396+
return MakeSharedArray<char>(bufferSize);
388397
case itk::IOComponentEnum::UCHAR:
389-
buffer = new unsigned char[bufferSize];
390-
break;
398+
return MakeSharedArray<unsigned char>(bufferSize);
391399
case itk::IOComponentEnum::USHORT:
392-
buffer = new unsigned short[bufferSize];
393-
break;
400+
return MakeSharedArray<unsigned short>(bufferSize);
394401
case itk::IOComponentEnum::SHORT:
395-
buffer = new short[bufferSize];
396-
break;
402+
return MakeSharedArray<short>(bufferSize);
397403
case itk::IOComponentEnum::UINT:
398-
buffer = new unsigned int[bufferSize];
399-
break;
404+
return MakeSharedArray<unsigned int>(bufferSize);
400405
case itk::IOComponentEnum::INT:
401-
buffer = new unsigned int[bufferSize];
402-
break;
406+
return MakeSharedArray<int>(bufferSize);
403407
case itk::IOComponentEnum::ULONG:
404-
buffer = new unsigned long[bufferSize];
405-
break;
408+
return MakeSharedArray<unsigned long>(bufferSize);
406409
case itk::IOComponentEnum::LONG:
407-
buffer = new long[bufferSize];
408-
break;
410+
return MakeSharedArray<long>(bufferSize);
409411
case itk::IOComponentEnum::LONGLONG:
410-
buffer = new long long[bufferSize];
411-
break;
412+
return MakeSharedArray<long long>(bufferSize);
412413
case itk::IOComponentEnum::ULONGLONG:
413-
buffer = new unsigned long long[bufferSize];
414-
break;
414+
return MakeSharedArray<unsigned long long>(bufferSize);
415415
case itk::IOComponentEnum::FLOAT:
416-
buffer = new float[bufferSize];
417-
break;
416+
return MakeSharedArray<float>(bufferSize);
418417
case itk::IOComponentEnum::DOUBLE:
419-
buffer = new double[bufferSize];
420-
break;
418+
return MakeSharedArray<double>(bufferSize);
421419
case itk::IOComponentEnum::LDOUBLE:
422-
buffer = new long double[bufferSize];
423-
break;
420+
return MakeSharedArray<long double>(bufferSize);
424421
case itk::IOComponentEnum::UNKNOWNCOMPONENTTYPE:
425422
break;
426423
default:
427424
break;
428425
}
429426

430-
*data = buffer;
427+
return nullptr;
431428
}
432429

430+
} // namespace MeshIOTestHelper
431+
} // namespace itk
432+
433433
#endif

Modules/IO/MeshFreeSurfer/test/itkFreeSurferMeshIOTest.cxx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,31 @@ itkFreeSurferMeshIOTestHelper(typename TMeshIO::Pointer fsMeshIO,
7979

8080
itk::SizeValueType cellBufferSize = 2000;
8181

82-
void * pointBuffer = nullptr;
83-
AllocateBuffer(&pointBuffer, fsMeshIO->GetPointComponentType(), pointBufferSize);
82+
const std::shared_ptr<void> pointBuffer =
83+
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetPointComponentType(), pointBufferSize);
84+
const std::shared_ptr<void> pointDataBuffer =
85+
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
86+
const std::shared_ptr<void> cellBuffer =
87+
itk::MeshIOTestHelper::AllocateBuffer(fsMeshIO->GetCellComponentType(), cellBufferSize);
8488

85-
void * pointDataBuffer = nullptr;
86-
AllocateBuffer(&pointDataBuffer, fsMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
89+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPoints(pointBuffer.get()));
90+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPointData(pointDataBuffer.get()));
8791

88-
void * cellBuffer = nullptr;
89-
AllocateBuffer(&cellBuffer, fsMeshIO->GetCellComponentType(), cellBufferSize);
90-
91-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPoints(pointBuffer));
92-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadPointData(pointDataBuffer));
93-
94-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadCells(cellBuffer));
92+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->ReadCells(cellBuffer.get()));
9593

9694
void * cellDataBuffer = nullptr;
9795
// Not used; empty method body; called for coverage purposes
9896
fsMeshIO->ReadCellData(cellDataBuffer);
9997

10098
// Test writing exceptions
10199
fsMeshIO->SetFileName("");
102-
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePoints(pointBuffer));
100+
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePoints(pointBuffer.get()));
103101
if (dynamic_cast<itk::FreeSurferBinaryMeshIO *>(fsMeshIO.GetPointer()))
104102
{
105-
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer));
103+
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer.get()));
106104
}
107105

108-
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteCells(cellBuffer));
106+
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteCells(cellBuffer.get()));
109107
ITK_TRY_EXPECT_EXCEPTION(fsMeshIO->WriteMeshInformation());
110108

111109
ITK_TEST_EXPECT_TRUE(!fsMeshIO->CanWriteFile(notAFsOutputFileName));
@@ -114,10 +112,10 @@ itkFreeSurferMeshIOTestHelper(typename TMeshIO::Pointer fsMeshIO,
114112
fsMeshIO->SetFileName(outputFileName);
115113

116114
// Write the actual data
117-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePoints(pointBuffer));
118-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer));
115+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePoints(pointBuffer.get()));
116+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WritePointData(pointDataBuffer.get()));
119117

120-
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WriteCells(cellBuffer));
118+
ITK_TRY_EXPECT_NO_EXCEPTION(fsMeshIO->WriteCells(cellBuffer.get()));
121119

122120
// Not used; empty method body; called for coverage purposes
123121
fsMeshIO->WriteCellData(cellDataBuffer);
@@ -148,12 +146,6 @@ itkFreeSurferMeshIOTestHelper(typename TMeshIO::Pointer fsMeshIO,
148146
ITK_TEST_EXPECT_EQUAL(fsMeshIO->GetNumberOfCellPixelComponents(),
149147
readWritefsMeshIO->GetNumberOfCellPixelComponents());
150148

151-
152-
::operator delete(pointBuffer);
153-
::operator delete(pointDataBuffer);
154-
::operator delete(cellBuffer);
155-
::operator delete(cellDataBuffer);
156-
157149
return testStatus;
158150
}
159151

Modules/IO/MeshGifti/test/itkGiftiMeshIOTest.cxx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,10 @@ itkGiftiMeshIOTest(int argc, char * argv[])
5353
giftiMeshIO->SetFileName(inputFileName);
5454
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadMeshInformation());
5555

56-
void * pointBuffer = nullptr;
57-
void * pointDataBuffer = nullptr;
58-
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadPoints(pointBuffer));
59-
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadPointData(pointDataBuffer));
60-
61-
void * cellBuffer = nullptr;
62-
void * cellDataBuffer = nullptr;
63-
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadCells(cellBuffer));
64-
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadCellData(cellDataBuffer));
56+
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadPoints(nullptr));
57+
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadPointData(nullptr));
58+
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadCells(nullptr));
59+
ITK_TRY_EXPECT_EXCEPTION(giftiMeshIO->ReadCellData(nullptr));
6560

6661
// Until the mesh information is read, the label color and name tables should be empty
6762
ITK_TEST_SET_GET_NULL_VALUE(giftiMeshIO->GetLabelColorTable());
@@ -146,17 +141,20 @@ itkGiftiMeshIOTest(int argc, char * argv[])
146141
itk::SizeValueType cellBufferSize = 1000000;
147142
itk::SizeValueType cellDataBufferSize = 1000000;
148143

149-
AllocateBuffer(&pointBuffer, giftiMeshIO->GetPointComponentType(), pointBufferSize);
150-
AllocateBuffer(&pointDataBuffer, giftiMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
151-
152-
AllocateBuffer(&cellBuffer, giftiMeshIO->GetCellComponentType(), cellBufferSize);
153-
AllocateBuffer(&cellDataBuffer, giftiMeshIO->GetCellPixelComponentType(), cellDataBufferSize);
144+
const std::shared_ptr<void> pointBuffer =
145+
itk::MeshIOTestHelper::AllocateBuffer(giftiMeshIO->GetPointComponentType(), pointBufferSize);
146+
const std::shared_ptr<void> pointDataBuffer =
147+
itk::MeshIOTestHelper::AllocateBuffer(giftiMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
148+
const std::shared_ptr<void> cellBuffer =
149+
itk::MeshIOTestHelper::AllocateBuffer(giftiMeshIO->GetCellComponentType(), cellBufferSize);
150+
const std::shared_ptr<void> cellDataBuffer =
151+
itk::MeshIOTestHelper::AllocateBuffer(giftiMeshIO->GetCellPixelComponentType(), cellDataBufferSize);
154152

155-
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadPoints(pointBuffer));
156-
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadPointData(pointDataBuffer));
153+
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadPoints(pointBuffer.get()));
154+
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadPointData(pointDataBuffer.get()));
157155

158-
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadCells(cellBuffer));
159-
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadCellData(cellDataBuffer));
156+
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadCells(cellBuffer.get()));
157+
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->ReadCellData(cellDataBuffer.get()));
160158

161159
auto writeUpdatePointData = static_cast<bool>(std::stoi(argv[10]));
162160
giftiMeshIO->SetUpdatePointData(writeUpdatePointData);
@@ -192,11 +190,11 @@ itkGiftiMeshIOTest(int argc, char * argv[])
192190
ITK_TEST_EXPECT_TRUE(giftiMeshIO->CanWriteFile(outputFileName.c_str()));
193191

194192
// Write the actual data
195-
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WritePoints(pointBuffer));
196-
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WritePointData(pointDataBuffer));
193+
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WritePoints(pointBuffer.get()));
194+
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WritePointData(pointDataBuffer.get()));
197195

198-
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WriteCells(cellBuffer));
199-
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WriteCellData(cellDataBuffer));
196+
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WriteCells(cellBuffer.get()));
197+
// ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WriteCellData(cellDataBuffer.get()));
200198

201199
ITK_TRY_EXPECT_NO_EXCEPTION(giftiMeshIO->WriteMeshInformation());
202200

@@ -246,12 +244,6 @@ itkGiftiMeshIOTest(int argc, char * argv[])
246244
ITK_TEST_EXPECT_EQUAL(giftiMeshIO->GetNumberOfCellPixelComponents(),
247245
readWriteGiftiMeshIO->GetNumberOfCellPixelComponents());
248246

249-
250-
::operator delete(pointBuffer);
251-
::operator delete(pointDataBuffer);
252-
::operator delete(cellBuffer);
253-
::operator delete(cellDataBuffer);
254-
255247
std::cout << "Test finished." << std::endl;
256248
return testStatus;
257249
}

Modules/IO/MeshOBJ/test/itkOBJMeshIOTest.cxx

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ itkOBJMeshIOTest(int argc, char * argv[])
5151
objMeshIO->SetFileName(inputFileName);
5252
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->ReadMeshInformation());
5353

54-
void * pointBuffer = nullptr;
55-
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->ReadPoints(pointBuffer));
56-
57-
void * cellBuffer = nullptr;
58-
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->ReadCells(cellBuffer));
54+
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->ReadPoints(nullptr));
55+
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->ReadCells(nullptr));
5956

6057
inputFileName = argv[3];
6158
ITK_TEST_EXPECT_TRUE(!objMeshIO->CanReadFile(inputFileName.c_str()));
@@ -102,18 +99,18 @@ itkOBJMeshIOTest(int argc, char * argv[])
10299
itk::SizeValueType pointBufferSize = 100000;
103100
itk::SizeValueType pointDataBufferSize = 100000;
104101

105-
itk::SizeValueType cellBufferSize = 100000;
106-
AllocateBuffer(&pointBuffer, objMeshIO->GetPointComponentType(), pointBufferSize);
107-
108-
void * pointDataBuffer = nullptr;
109-
AllocateBuffer(&pointDataBuffer, objMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
110-
111-
AllocateBuffer(&cellBuffer, objMeshIO->GetCellComponentType(), cellBufferSize);
102+
itk::SizeValueType cellBufferSize = 100000;
103+
const std::shared_ptr<void> pointBuffer =
104+
itk::MeshIOTestHelper::AllocateBuffer(objMeshIO->GetPointComponentType(), pointBufferSize);
105+
const std::shared_ptr<void> pointDataBuffer =
106+
itk::MeshIOTestHelper::AllocateBuffer(objMeshIO->GetPointPixelComponentType(), pointDataBufferSize);
107+
const std::shared_ptr<void> cellBuffer =
108+
itk::MeshIOTestHelper::AllocateBuffer(objMeshIO->GetCellComponentType(), cellBufferSize);
112109

113-
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadPoints(pointBuffer));
114-
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadPointData(pointDataBuffer));
110+
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadPoints(pointBuffer.get()));
111+
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadPointData(pointDataBuffer.get()));
115112

116-
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadCells(cellBuffer));
113+
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->ReadCells(cellBuffer.get()));
117114

118115
void * cellDataBuffer = nullptr;
119116
// Not used; empty method body; called for coverage purposes
@@ -122,8 +119,8 @@ itkOBJMeshIOTest(int argc, char * argv[])
122119
// Test writing exceptions
123120
std::string outputFileName = "";
124121
objMeshIO->SetFileName(outputFileName);
125-
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->WritePoints(pointBuffer));
126-
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->WriteCells(cellBuffer));
122+
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->WritePoints(pointBuffer.get()));
123+
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->WriteCells(cellBuffer.get()));
127124
ITK_TRY_EXPECT_EXCEPTION(objMeshIO->WriteMeshInformation());
128125

129126
outputFileName = argv[4];
@@ -134,12 +131,12 @@ itkOBJMeshIOTest(int argc, char * argv[])
134131
objMeshIO->SetFileName(outputFileName);
135132

136133
// Write the actual data
137-
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->WritePoints(pointBuffer));
134+
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->WritePoints(pointBuffer.get()));
138135

139136
// Not used; empty method body; called for coverage purposes
140-
objMeshIO->WritePointData(pointDataBuffer);
137+
objMeshIO->WritePointData(pointDataBuffer.get());
141138

142-
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->WriteCells(cellBuffer));
139+
ITK_TRY_EXPECT_NO_EXCEPTION(objMeshIO->WriteCells(cellBuffer.get()));
143140

144141
// Not used; empty method body; called for coverage purposes
145142
objMeshIO->WriteCellData(cellDataBuffer);
@@ -179,11 +176,6 @@ itkOBJMeshIOTest(int argc, char * argv[])
179176
ITK_TEST_EXPECT_EQUAL(objMeshIO->GetNumberOfCellPixelComponents(),
180177
readWriteByuMeshIO->GetNumberOfCellPixelComponents());
181178

182-
183-
::operator delete(pointBuffer);
184-
::operator delete(pointDataBuffer);
185-
::operator delete(cellBuffer);
186-
187179
std::cout << "Test finished." << std::endl;
188180
return testStatus;
189181
}

0 commit comments

Comments
 (0)