From fcc7d6be108388a742866ef4dd6574bfd04504a5 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 23 Nov 2014 23:40:31 -0800 Subject: [PATCH] SDMC: Use unique_ptr instead of manual allocation to prevent memory leaks --- source/tests/fs_sdmc.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/tests/fs_sdmc.cpp b/source/tests/fs_sdmc.cpp index 530a38d..fe99074 100644 --- a/source/tests/fs_sdmc.cpp +++ b/source/tests/fs_sdmc.cpp @@ -1,5 +1,6 @@ #include "tests/fs_sdmc.h" +#include #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 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);