From 57288890689bfa2c2d35882169a539813be621f1 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 15 Sep 2013 00:32:07 +0300 Subject: add RWops leaks reporting. --- src/utils/physfsrwops.cpp | 6 ++++++ src/utils/physfsrwops.h | 2 ++ src/utils/sdlcheckutils.cpp | 18 +++++++++--------- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src/utils') diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 022e8160f..aa5caf7c7 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -27,6 +27,7 @@ #include "logger.h" #include "utils/fuzzer.h" +#include "utils/physfscheckutils.h" #include @@ -160,6 +161,9 @@ static int physfsrwops_close(SDL_RWops *const rw) if (openedRWops <= 0) logger->log("closing already closed RWops"); openedRWops --; +#endif +#ifdef DEBUG_PHYSFS + FakePhysFSClose(rw); #endif return 0; } /* physfsrwops_close */ @@ -256,10 +260,12 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname) return create_rwops(PhysFs::openAppend(fname)); } /* PHYSFSRWOPS_openAppend */ +#ifdef DUMP_LEAKED_RESOURCES void reportRWops() { if (openedRWops) logger->log("leaking RWops: %d", openedRWops); } +#endif /* end of physfsrwops.c ... */ diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h index 45ee21cc4..7e859a234 100644 --- a/src/utils/physfsrwops.h +++ b/src/utils/physfsrwops.h @@ -79,6 +79,8 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname) A_WARN_UNUSED; */ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *const handle) A_WARN_UNUSED; +#ifdef DUMP_LEAKED_RESOURCES void reportRWops(); +#endif #endif // UTILS_PHYSFSRWOPS_H diff --git a/src/utils/sdlcheckutils.cpp b/src/utils/sdlcheckutils.cpp index 50adedb28..3810672d9 100644 --- a/src/utils/sdlcheckutils.cpp +++ b/src/utils/sdlcheckutils.cpp @@ -35,10 +35,10 @@ #define DEBUG_SURFACE_ALLOCATION 1 -struct SurfaceObject +struct MemoryObject { - SurfaceObject(const std::string &name, const char *const file, - const unsigned int line) : + MemoryObject(const std::string &name, const char *const file, + const unsigned int line) : mName(name), mAddFile(strprintf("%s:%u", file, line)), mRemoveFile(), @@ -52,7 +52,7 @@ struct SurfaceObject int mCnt; }; -std::map mSurfaces; +std::map mSurfaces; static SDL_Surface *addSurface(const char *const name, SDL_Surface *const surface, @@ -63,11 +63,11 @@ static SDL_Surface *addSurface(const char *const name, logger->log("add surface: %s %s:%u %p", name, file, line, static_cast(surface)); #endif - std::map::iterator + std::map::iterator it = mSurfaces.find(surface); if (it != mSurfaces.end()) { - SurfaceObject *const obj = (*it).second; + MemoryObject *const obj = (*it).second; if (obj) { // found some time ago created surface #ifdef DEBUG_SURFACE_ALLOCATION @@ -80,7 +80,7 @@ static SDL_Surface *addSurface(const char *const name, } else { // creating surface object - mSurfaces[surface] = new SurfaceObject(name, file, line); + mSurfaces[surface] = new MemoryObject(name, file, line); } return surface; } @@ -93,7 +93,7 @@ static void deleteSurface(const char *const name A_UNUSED, #ifdef DEBUG_SURFACE_ALLOCATION logger->log("delete surface: %s %s:%u %p", name, file, line, surface); #endif - std::map::iterator + std::map::iterator it = mSurfaces.find(surface); if (it == mSurfaces.end()) { @@ -102,7 +102,7 @@ static void deleteSurface(const char *const name A_UNUSED, } else { - SurfaceObject *const obj = (*it).second; + MemoryObject *const obj = (*it).second; if (obj) { const int cnt = obj->mCnt; -- cgit v1.2.3-70-g09d2