From 5c9f0b93d2ff01c2cefe250d27fde335664e9d60 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 14 May 2022 18:36:44 +0100 Subject: [PATCH] couple of surface/script mem leak fixes proposal. --- lib/xgraph/xgraph.cpp | 26 ++++++++++++-------------- lib/xgraph/xgraph.h | 6 +++--- lib/xtool/xglobal.h | 1 + src/actint/ascript.cpp | 4 ++-- src/global.h | 1 + 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/xgraph/xgraph.cpp b/lib/xgraph/xgraph.cpp index 1e5fdf1f..4017c7d1 100644 --- a/lib/xgraph/xgraph.cpp +++ b/lib/xgraph/xgraph.cpp @@ -221,9 +221,9 @@ int XGR_Screen::init(int x,int y,int flags_in) } void XGR_Screen::create_surfaces(int width, int height) { - XGR_ScreenSurface = new uint8_t[width * height] {0}; - XGR_ScreenSurface2D = new uint8_t[width * height] {0}; - XGR_ScreenSurface2DRgba = new uint32_t[width * height] {0}; + XGR_ScreenSurface.reset(new uint8_t[width * height] {0}); + XGR_ScreenSurface2D.reset(new uint8_t[width * height] {0}); + XGR_ScreenSurface2DRgba.reset(new uint32_t[width * height] {0}); std::cout<<"XGR32_ScreenSurface = SDL_CreateRGBSurface"< XGR_ScreenSurface; + std::unique_ptr XGR_ScreenSurface2D; + std::unique_ptr XGR_ScreenSurface2DRgba; SDL_Surface *XGR32_ScreenSurface; SDL_Surface *IconSurface; diff --git a/lib/xtool/xglobal.h b/lib/xtool/xglobal.h index 4d732a2d..4e0128a3 100644 --- a/lib/xtool/xglobal.h +++ b/lib/xtool/xglobal.h @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef __WORDSIZE #else diff --git a/src/actint/ascript.cpp b/src/actint/ascript.cpp index 6a978509..724bea40 100644 --- a/src/actint/ascript.cpp +++ b/src/actint/ascript.cpp @@ -581,7 +581,7 @@ aciLocationShutterInfo* locSh; aciWorldMap* wMap; aciWorldInfo* wData; -actIntDispatcher* aScrDisp; +std::unique_ptr aScrDisp; int aciCurCredits03 = 0; @@ -605,7 +605,7 @@ void aParseScript(const char* fname,const char* bname) invMatrix* mtx; invItem* itm; - aScrDisp = new actIntDispatcher; + aScrDisp.reset(new actIntDispatcher); aciML_D = new aciML_Dispatcher; #ifndef _BINARY_SCRIPT_ diff --git a/src/global.h b/src/global.h index bc9e3c31..d938f6db 100644 --- a/src/global.h +++ b/src/global.h @@ -8,6 +8,7 @@ #include #include #include +#include #if (defined(__unix__) || defined(__APPLE__)) #include