EMI: Fix memleaks caused by specialtyTextures

- delete screenshot after texture is created
- free _data[] entries in BitmapData::freeData()
- destroy _specialtyTextures[] entries in
  graphic driver's destructors
This commit is contained in:
Christian Krause 2014-12-31 01:42:44 +01:00
parent 026166ecf6
commit ad2ce4a87e
5 changed files with 15 additions and 2 deletions

View File

@ -233,6 +233,9 @@ BitmapData::~BitmapData() {
void BitmapData::freeData() {
if (!_keepData) {
for (int i = 0; i < _numImages; ++i) {
_data[i].free();
}
delete[] _data;
_data = nullptr;
}

View File

@ -480,7 +480,6 @@ void Lua_V2::ThumbnailFromFile() {
const char *filename = lua_getstring(filenameObj);
int width = 256, height = 128;
Bitmap *screenshot;
SaveGame *savedState = SaveGame::openForLoading(filename);
if (!savedState || !savedState->isCompatible()) {
@ -501,10 +500,11 @@ void Lua_V2::ThumbnailFromFile() {
data[l] = savedState->readLEUint16();
}
Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
screenshot = new Bitmap(buf, width, height, "screenshot");
Bitmap *screenshot = new Bitmap(buf, width, height, "screenshot");
if (!screenshot) {
lua_pushnil();
warning("Lua_V2::ThumbnailFromFile: Could not restore screenshot from file %s", filename);
delete screenshot;
delete[] data;
delete savedState;
return;
@ -512,6 +512,7 @@ void Lua_V2::ThumbnailFromFile() {
screenshot->_data->convertToColorFormat(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
g_driver->createSpecialtyTexture(index, screenshot->getData(0).getRawBuffer(), width, height);
delete screenshot;
delete[] data;
savedState->endSection();
delete savedState;

View File

@ -124,6 +124,9 @@ GfxOpenGL::~GfxOpenGL() {
if (_useDimShader)
glDeleteProgramsARB(1, &_dimFragProgram);
#endif
for (unsigned int i = 0; i < _numSpecialtyTextures; i++) {
destroyTexture(&_specialtyTextures[i]);
}
}
byte *GfxOpenGL::setupScreen(int screenW, int screenH, bool fullscreen) {

View File

@ -239,6 +239,9 @@ GfxOpenGLS::GfxOpenGLS() {
}
GfxOpenGLS::~GfxOpenGLS() {
for (unsigned int i = 0; i < _numSpecialtyTextures; i++) {
destroyTexture(&_specialtyTextures[i]);
}
delete[] _lights;
delete _backgroundProgram;

View File

@ -64,6 +64,9 @@ GfxTinyGL::GfxTinyGL() :
}
GfxTinyGL::~GfxTinyGL() {
for (unsigned int i = 0; i < _numSpecialtyTextures; i++) {
destroyTexture(&_specialtyTextures[i]);
}
if (_zb) {
delBuffer(1);
TinyGL::glClose();