diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-14 23:20:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-14 23:20:17 +0300 |
commit | 53947c9d39440424dcf815ea5df130e833457437 (patch) | |
tree | d9c5014580d81a0d6d809c862fd633ad95d6af72 /src | |
parent | 0c0784ac13663c4e33be50fba8c5e4299bad0ead (diff) | |
download | plus-53947c9d39440424dcf815ea5df130e833457437.tar.gz plus-53947c9d39440424dcf815ea5df130e833457437.tar.bz2 plus-53947c9d39440424dcf815ea5df130e833457437.tar.xz plus-53947c9d39440424dcf815ea5df130e833457437.zip |
add rwops leak detection.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/utils/physfsrwops.cpp | 20 | ||||
-rw-r--r-- | src/utils/physfsrwops.h | 2 |
3 files changed, 24 insertions, 0 deletions
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 <stdio.h> @@ -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 |