From 53947c9d39440424dcf815ea5df130e833457437 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 14 Sep 2013 23:20:17 +0300 Subject: add rwops leak detection. --- src/main.cpp | 2 ++ src/utils/physfsrwops.cpp | 20 ++++++++++++++++++++ src/utils/physfsrwops.h | 2 ++ 3 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 5141951ed..236847ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,7 @@ #include "utils/mkdir.h" #endif #include "utils/paths.h" +#include "utils/physfsrwops.h" #include "utils/process.h" #include "utils/physfstools.h" #include "utils/xml.h" @@ -309,6 +310,7 @@ int main(int argc, char *argv[]) } delete client; client = nullptr; + reportRWops(); return ret; } diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index 31b86058c..022e8160f 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -24,6 +24,8 @@ #include "utils/physfsrwops.h" +#include "logger.h" + #include "utils/fuzzer.h" #include @@ -38,6 +40,10 @@ #define PHYSFSSIZE int #endif +#ifdef DUMP_LEAKED_RESOURCES +static int openedRWops = 0; +#endif + static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset, const int whence) { @@ -150,6 +156,11 @@ static int physfsrwops_close(SDL_RWops *const rw) } /* if */ SDL_FreeRW(rw); +#ifdef DUMP_LEAKED_RESOURCES + if (openedRWops <= 0) + logger->log("closing already closed RWops"); + openedRWops --; +#endif return 0; } /* physfsrwops_close */ @@ -184,6 +195,9 @@ static SDL_RWops *create_rwops(PHYSFS_file *const handle) retval->close = physfsrwops_close; retval->hidden.unknown.data1 = handle; } /* if */ +#ifdef DUMP_LEAKED_RESOURCES + openedRWops ++; +#endif } /* else */ return retval; @@ -242,4 +256,10 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname) return create_rwops(PhysFs::openAppend(fname)); } /* PHYSFSRWOPS_openAppend */ +void reportRWops() +{ + if (openedRWops) + logger->log("leaking RWops: %d", openedRWops); +} + /* end of physfsrwops.c ... */ diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h index fb0285e0a..45ee21cc4 100644 --- a/src/utils/physfsrwops.h +++ b/src/utils/physfsrwops.h @@ -79,4 +79,6 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname) A_WARN_UNUSED; */ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *const handle) A_WARN_UNUSED; +void reportRWops(); + #endif // UTILS_PHYSFSRWOPS_H -- cgit v1.2.3-70-g09d2