Move guarded objetc allocation to a guardedalloc header

Also made libmv-capi use guarded objetc allocation.
Run into some suspecious cases when it was not so
clear whether memory is being freed or not.

Now we'll know for sure whether there're leaks or not :)

Having this macros in a guardedalloc header helps
using them in other areas (for now it's OCIO and libmv,
but in the future it'll be more places).
This commit is contained in:
Sergey Sharybin
2013-10-09 08:46:02 +00:00
parent 22a30f78f2
commit 49bc310671
6 changed files with 100 additions and 60 deletions

View File

@@ -244,6 +244,24 @@ public: \
MEM_freeN(mem); \
} \
#if defined __GNUC__ || defined __sun
# define OBJECT_GUARDED_NEW(type, args ...) \
new(MEM_mallocN(sizeof(type), __func__)) type(args)
#else
# define OBJECT_GUARDED_NEW(type, ...) \
new(MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__)
#endif
#define OBJECT_GUARDED_DELETE(what, type) \
{ if(what) { \
((type*)(what))->~type(); \
MEM_freeN(what); \
} } (void)0
#define OBJECT_GUARDED_DELETE_ARRAY(what, type, count) \
{ if(what) { \
for (int i = 0; i < count; i++) ((type*)(what))[i].~type(); \
MEM_freeN(what); \
} } (void)0
#endif /* __cplusplus */
#ifdef __cplusplus