SDMC: Use unique_ptr instead of manual allocation to prevent memory leaks

This commit is contained in:
archshift 2014-11-23 23:40:31 -08:00
parent a95803b96b
commit fcc7d6be10

View File

@ -1,5 +1,6 @@
#include "tests/fs_sdmc.h"
#include <memory>
#include <3ds.h>
#include "tests/test.h"
@ -80,14 +81,11 @@ static bool TestFileWriteRead(FS_archive sdmcArchive)
// Verify file size
SoftAssert(fileSize == bytesWritten);
char* stringRead = new char[fileSize];
std::unique_ptr<char> stringRead(new char[fileSize]);
// Read from file
SoftAssert(FSFILE_Read(fileHandle, &bytesRead, 0, stringRead, fileSize) == 0);
// Verify string size
SoftAssert(bytesRead == bytesWritten);
SoftAssert(FSFILE_Read(fileHandle, &bytesRead, 0, stringRead.get(), fileSize) == 0);
// Verify string contents
SoftAssert(strcmp(stringRead, stringWritten) == 0);
delete[] stringRead;
SoftAssert(strcmp(stringRead.get(), stringWritten) == 0);
FSFILE_Close(fileHandle);
FSUSER_DeleteFile(NULL, sdmcArchive, filePath);