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/utils/physfsrwops.cpp | |
parent | 0c0784ac13663c4e33be50fba8c5e4299bad0ead (diff) | |
download | manaverse-53947c9d39440424dcf815ea5df130e833457437.tar.gz manaverse-53947c9d39440424dcf815ea5df130e833457437.tar.bz2 manaverse-53947c9d39440424dcf815ea5df130e833457437.tar.xz manaverse-53947c9d39440424dcf815ea5df130e833457437.zip |
add rwops leak detection.
Diffstat (limited to 'src/utils/physfsrwops.cpp')
-rw-r--r-- | src/utils/physfsrwops.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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 ... */ |