aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/psp
diff options
context:
space:
mode:
authorD G Turner2018-10-07 21:23:29 +0100
committerD G Turner2018-10-07 21:23:29 +0100
commit9c1dfe41aaecc01702ed5ff01c07d9ece5d8bb39 (patch)
tree791d8348226bc86d1ccabfa3d92eab7873e25f1f /backends/platform/psp
parent5390c258d2f2e6df45a4be9d647be3db5f085933 (diff)
downloadscummvm-rg350-9c1dfe41aaecc01702ed5ff01c07d9ece5d8bb39.tar.gz
scummvm-rg350-9c1dfe41aaecc01702ed5ff01c07d9ece5d8bb39.tar.bz2
scummvm-rg350-9c1dfe41aaecc01702ed5ff01c07d9ece5d8bb39.zip
PSP: Fix Minor Memory Access Error and Leaks in Backend Code.
This is as per bug Trac #10654.
Diffstat (limited to 'backends/platform/psp')
-rw-r--r--backends/platform/psp/display_manager.cpp2
-rw-r--r--backends/platform/psp/tests.cpp31
2 files changed, 32 insertions, 1 deletions
diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp
index fd94827e04..9643063294 100644
--- a/backends/platform/psp/display_manager.cpp
+++ b/backends/platform/psp/display_manager.cpp
@@ -117,9 +117,9 @@ void VramAllocator::deallocate(void *address) {
// Find the Allocator to deallocate
for (i = _allocList.begin(); i != _allocList.end(); ++i) {
if ((*i).address == address) {
+ PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
_bytesAllocated -= (*i).size;
_allocList.erase(i);
- PSP_DEBUG_PRINT("Deallocated address[%p], size[%u]\n", (*i).address, (*i).size);
return;
}
}
diff --git a/backends/platform/psp/tests.cpp b/backends/platform/psp/tests.cpp
index 92a18e58d0..450a48e563 100644
--- a/backends/platform/psp/tests.cpp
+++ b/backends/platform/psp/tests.cpp
@@ -566,6 +566,7 @@ bool PspUnitTests::testFileSystem() {
wrStream = file.createWriteStream();
if (!wrStream) {
PSP_ERROR("%s couldn't be created.\n", path);
+ delete[] buffer;
return false;
}
@@ -579,6 +580,8 @@ bool PspUnitTests::testFileSystem() {
while(totalLength - curLength > 0) {
if ((int)wrStream->write(index, curLength) != curLength) {
PSP_ERROR("couldn't write %d bytes\n", curLength);
+ delete[] buffer;
+ delete wrStream;
return false;
}
totalLength -= curLength;
@@ -590,6 +593,8 @@ bool PspUnitTests::testFileSystem() {
// write the rest
if ((int)wrStream->write(index, totalLength) != totalLength) {
PSP_ERROR("couldn't write %d bytes\n", curLength);
+ delete[] buffer;
+ delete wrStream;
return false;
}
@@ -600,12 +605,15 @@ bool PspUnitTests::testFileSystem() {
rdStream = file.createReadStream();
if (!rdStream) {
PSP_ERROR("%s couldn't be created.\n", path);
+ delete[] buffer;
return false;
}
// seek to beginning
if (!rdStream->seek(0, SEEK_SET)) {
PSP_ERROR("couldn't seek to the beginning after writing the file\n");
+ delete[] buffer;
+ delete rdStream;
return false;
}
@@ -619,6 +627,9 @@ bool PspUnitTests::testFileSystem() {
if (!rdStream->eos()) {
PSP_ERROR("didn't find EOS at end of stream\n");
+ delete[] buffer;
+ delete rdStream;
+ delete[] readBuffer;
return false;
}
@@ -626,6 +637,9 @@ bool PspUnitTests::testFileSystem() {
for (i=0; i<(int)BufSize; i++)
if (buffer[i] != readBuffer[i]) {
PSP_ERROR("reading/writing mistake at %x. Got %x instead of %x\n", i, readBuffer[i], buffer[i]);
+ delete[] buffer;
+ delete rdStream;
+ delete[] readBuffer;
return false;
}
@@ -636,7 +650,9 @@ bool PspUnitTests::testFileSystem() {
}
}
+ delete[] buffer;
delete rdStream;
+ delete[] readBuffer;
PSP_INFO_PRINT("writing...\n");
@@ -652,12 +668,14 @@ bool PspUnitTests::testFileSystem() {
int ret;
if ((ret = wrStream->write(phrase, phraseLen)) != (int)phraseLen) {
PSP_ERROR("couldn't write phrase. Got %d instead of %d\n", ret, phraseLen);
+ delete wrStream;
return false;
}
PSP_INFO_PRINT("reading...\n");
delete wrStream;
+
rdStream = file.createReadStream();
if (!rdStream) {
PSP_ERROR("%s couldn't be created.\n", path);
@@ -669,12 +687,16 @@ bool PspUnitTests::testFileSystem() {
if ((ret = rdStream->read(readPhrase, phraseLen) != phraseLen)) {
PSP_ERROR("read error on phrase. Got %d instead of %d\n", ret, phraseLen);
+ delete rdStream;
+ delete[] readPhrase;
return false;
}
for (i=0; i<(int)phraseLen; i++) {
if (readPhrase[i] != phrase[i]) {
PSP_ERROR("bad read/write in phrase. At %d, %x != %x\n", i, readPhrase[i], phrase[i]);
+ delete rdStream;
+ delete[] readPhrase;
return false;
}
}
@@ -682,6 +704,8 @@ bool PspUnitTests::testFileSystem() {
// check for exceeding
if (readPhrase[i] != 0) {
PSP_ERROR("found excessive copy in phrase. %c at %d\n", readPhrase[i], i);
+ delete rdStream;
+ delete[] readPhrase;
return false;
}
@@ -690,15 +714,22 @@ bool PspUnitTests::testFileSystem() {
// seek to end
if (!rdStream->seek(0, SEEK_END)) {
PSP_ERROR("couldn't seek to end for append\n");
+ delete rdStream;
+ delete[] readPhrase;
return false;
};
// try to read
if (rdStream->read(readPhrase, 2) || !rdStream->eos()) {
PSP_ERROR("was able to read at end of file\n");
+ delete rdStream;
+ delete[] readPhrase;
return false;
}
+ delete rdStream;
+ delete[] readPhrase;
+
PSP_INFO_PRINT("ok\n");
return true;
}