mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 14:18:37 +00:00
GLK: SCOTT: Fix leak in disk_image.cpp
The method diCreateFromData() is set up as if it is going to copy the data supplied by the caller to the _image member, allocating memory for it, but then just assigns the data to it instead, leaking the allocated memory. This also means that if the data supplied is not a valid disk image, it will delete the original data in the default case. We fix this by just removing the allocation and the deletion. An alternative would have been to actually copy the data instead.
This commit is contained in:
parent
2a8664e18e
commit
387dd08f5d
@ -744,18 +744,14 @@ RawDirEntry *findLargestFileEntry(DiskImage *di) {
|
||||
DiskImage *diCreateFromData(uint8_t *data, int length) {
|
||||
DiskImage *di;
|
||||
|
||||
if (data == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if ((di = new DiskImage) == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
di->_size = length;
|
||||
|
||||
/* allocate buffer for image */
|
||||
if ((di->_image = new byte[length]) == nullptr) {
|
||||
delete di;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
di->_image = data;
|
||||
|
||||
di->_errinfo = nullptr;
|
||||
@ -798,7 +794,6 @@ DiskImage *diCreateFromData(uint8_t *data, int length) {
|
||||
break;
|
||||
|
||||
default:
|
||||
delete[] di->_image;
|
||||
delete di;
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user