Move guarded objetc allocation to a guardedalloc header
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 9 Oct 2013 08:46:02 +0000 (08:46 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 9 Oct 2013 08:46:02 +0000 (08:46 +0000)
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).

extern/libmv/CMakeLists.txt
extern/libmv/SConscript
extern/libmv/bundle.sh
extern/libmv/libmv-capi.cc
intern/guardedalloc/MEM_guardedalloc.h
intern/opencolorio/ocio_impl.cc

index 2c9a21965f01c8693bd1e0e842e64b0fea7e083b..ae5cfd0cb1d558109f31f373e64ee490672d1763 100644 (file)
@@ -37,10 +37,13 @@ set(SRC
 if(WITH_LIBMV)
        add_definitions(
                -DWITH_LIBMV
+               -DWITH_LIBMV_GUARDED_ALLOC
+               -DGOOGLE_GLOG_DLL_DECL=
        )
 
        list(APPEND INC
                third_party/ceres/include
+               ../../intern/guardedalloc
        )
 
        set(INC_SYS
@@ -224,10 +227,6 @@ if(WITH_LIBMV)
                        third_party/glog/src
                )
        endif()
-
-       add_definitions(
-               -DGOOGLE_GLOG_DLL_DECL=
-       )
 else()
        list(APPEND SRC
                libmv-capi_stub.cc
index f422eb08c5838946bac088e681401308756dafcf..6926b36f335a60644d4afef8f5e3f301b8a69438 100644 (file)
@@ -15,6 +15,7 @@ incs = '.'
 if env['WITH_BF_LIBMV']:
     defs.append('GOOGLE_GLOG_DLL_DECL=')
     defs.append('WITH_LIBMV')
+    defs.append('WITH_LIBMV_GUARDED_ALLOC')
 
     src = env.Glob("libmv-capi.cc")
     src += env.Glob('libmv/image/*.cc')
@@ -25,7 +26,7 @@ if env['WITH_BF_LIBMV']:
     src += env.Glob('third_party/fast/*.c')
     src += env.Glob('third_party/gflags/*.cc')
 
-    incs += ' ../Eigen3 third_party/ceres/include'
+    incs += ' ../Eigen3 third_party/ceres/include ../../intern/guardedalloc'
     incs += ' ' + env['BF_PNG_INC']
     incs += ' ' + env['BF_ZLIB_INC']
 
index 16fb754d30ab8f47fcaafd21ea68f9b95205988d..f51af8ee32e7a7d7fe610c65835de33c1fd2665f 100755 (executable)
@@ -133,6 +133,8 @@ set(SRC
 if(WITH_LIBMV)
        add_definitions(
                -DWITH_LIBMV
+               -DWITH_LIBMV_GUARDED_ALLOC
+               -DGOOGLE_GLOG_DLL_DECL=
        )
 
        list(APPEND INC
@@ -203,10 +205,6 @@ ${third_glog_headers}
                        third_party/glog/src
                )
        endif()
-
-       add_definitions(
-               -DGOOGLE_GLOG_DLL_DECL=
-       )
 else()
        list(APPEND SRC
                libmv-capi_stub.cc
@@ -238,11 +236,12 @@ incs = '.'
 if env['WITH_BF_LIBMV']:
     defs.append('GOOGLE_GLOG_DLL_DECL=')
     defs.append('WITH_LIBMV')
+    defs.append('WITH_LIBMV_GUARDED_ALLOC')
 
     src = env.Glob("libmv-capi.cc")
 $src
 
-    incs += ' ../Eigen3 third_party/ceres/include'
+    incs += ' ../Eigen3 third_party/ceres/include ../../intern/guardedalloc'
     incs += ' ' + env['BF_PNG_INC']
     incs += ' ' + env['BF_ZLIB_INC']
 
index 396928ba8ba3979a1dde35391e3e1f68843f33cf..a7509fd6b45e780af55865df9e12efe2a929a23c 100644 (file)
 #  include <png.h>
 #endif
 
-#include "libmv/logging/logging.h"
+#ifdef WITH_LIBMV_GUARDED_ALLOC
+#  include "MEM_guardedalloc.h"
+#  define LIBMV_OBJECT_NEW OBJECT_GUARDED_NEW
+#  define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
+#  define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
+#  define LIBMV_OBJECT_DELETE_ARRAY OBJECT_GUARDED_DELETE_ARRAY
+#else
+// Need this to keep libmv-capi potentially standalone.
+#  if defined __GNUC__ || defined __sun
+#    define LIBMV_OBJECT_NEW(type, args ...) \
+       new(malloc(sizeof(type))) type(args)
+#  else
+#    define LIBMV_OBJECT_NEW(type, ...) \
+       new(malloc(sizeof(type))) type(__VA_ARGS__)
+#endif
+#  define LIBMV_OBJECT_DELETE(what, type) \
+       { if(what) { \
+                       ((type*)(what))->~type(); \
+                       free(what); \
+       } } (void)0
+#define LIBMV_OBJECT_DELETE_ARRAY(what, type, count) \
+       { if(what) { \
+                       for (int i = 0; i < count; i++) ((type*)(what))[i].~type(); \
+                       free(what); \
+       } } (void)0
+#endif
 
+#include "libmv/logging/logging.h"
+#include "libmv/multiview/homography.h"
 #include "libmv/tracking/track_region.h"
-
 #include "libmv/simple_pipeline/callbacks.h"
 #include "libmv/simple_pipeline/tracks.h"
 #include "libmv/simple_pipeline/initialize_reconstruction.h"
@@ -58,8 +84,6 @@
 #include "libmv/simple_pipeline/reconstruction_scale.h"
 #include "libmv/simple_pipeline/keyframe_selection.h"
 
-#include "libmv/multiview/homography.h"
-
 #ifdef _MSC_VER
 #  define snprintf _snprintf
 #endif
@@ -388,14 +412,15 @@ void libmv_samplePlanarPatch(const float *image, int width, int height,
 
 struct libmv_Tracks *libmv_tracksNew(void)
 {
-       libmv::Tracks *libmv_tracks = new libmv::Tracks();
+       libmv::Tracks *libmv_tracks = LIBMV_OBJECT_NEW(libmv::Tracks);
 
        return (struct libmv_Tracks *)libmv_tracks;
 }
 
 void libmv_tracksDestroy(struct libmv_Tracks *libmv_tracks)
 {
-       delete (libmv::Tracks*) libmv_tracks;
+       using libmv::Tracks;
+       LIBMV_OBJECT_DELETE(libmv_tracks, Tracks);
 }
 
 void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y)
@@ -578,7 +603,7 @@ struct libmv_Reconstruction *libmv_solveReconstruction(const struct libmv_Tracks
                reconstruct_progress_update_cb progress_update_callback,
                void *callback_customdata)
 {
-       struct libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
+       struct libmv_Reconstruction *libmv_reconstruction = LIBMV_OBJECT_NEW(libmv_Reconstruction);
 
        libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks);
        libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction;
@@ -660,7 +685,7 @@ struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_t
                reconstruct_progress_update_cb progress_update_callback,
                void *callback_customdata)
 {
-       struct libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
+       struct libmv_Reconstruction *libmv_reconstruction = LIBMV_OBJECT_NEW(libmv_Reconstruction);
 
        libmv::Tracks &tracks = *((libmv::Tracks *) libmv_tracks);
        libmv::EuclideanReconstruction &reconstruction = libmv_reconstruction->reconstruction;
@@ -703,7 +728,7 @@ struct libmv_Reconstruction *libmv_solveModal(const struct libmv_Tracks *libmv_t
 
 void libmv_reconstructionDestroy(struct libmv_Reconstruction *libmv_reconstruction)
 {
-       delete libmv_reconstruction;
+       LIBMV_OBJECT_DELETE(libmv_reconstruction, libmv_Reconstruction);
 }
 
 int libmv_reprojectionPointForTrack(const struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3])
@@ -850,7 +875,7 @@ struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data,
 {
        libmv::Feature *features = NULL;
        std::vector<libmv::Feature> v;
-       struct libmv_Features *libmv_features = new libmv_Features();
+       struct libmv_Features *libmv_features = LIBMV_OBJECT_NEW(libmv_Features);
        int i = 0, count;
 
        if (margin) {
@@ -864,7 +889,7 @@ struct libmv_Features *libmv_detectFeaturesFAST(const unsigned char *data,
        count = v.size();
 
        if (count) {
-               features = new libmv::Feature[count];
+               features = LIBMV_OBJECT_NEW(libmv::Feature[count]);
 
                for(std::vector<libmv::Feature>::iterator it = v.begin(); it != v.end(); it++) {
                        features[i++] = *it;
@@ -883,7 +908,7 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data,
                                                    int margin, int count, int min_distance)
 {
        libmv::Feature *features = NULL;
-       struct libmv_Features *libmv_features = new libmv_Features;
+       struct libmv_Features *libmv_features = LIBMV_OBJECT_NEW(libmv_Features);
 
        if (count) {
                if (margin) {
@@ -892,7 +917,7 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data,
                        height -= 2 * margin;
                }
 
-               features = new libmv::Feature[count];
+               features = LIBMV_OBJECT_NEW(libmv::Feature[count]);
                libmv::DetectMORAVEC(data, stride, width, height, features, &count, min_distance, NULL);
        }
 
@@ -905,10 +930,12 @@ struct libmv_Features *libmv_detectFeaturesMORAVEC(const unsigned char *data,
 
 void libmv_featuresDestroy(struct libmv_Features *libmv_features)
 {
-       if (libmv_features->features)
-               delete [] libmv_features->features;
+       if (libmv_features->features) {
+               using libmv::Feature;
+               LIBMV_OBJECT_DELETE_ARRAY(libmv_features->features, Feature, libmv_features->count);
+       }
 
-       delete libmv_features;
+       LIBMV_OBJECT_DELETE(libmv_features, libmv_Features);
 }
 
 int libmv_countFeatures(const struct libmv_Features *libmv_features)
@@ -930,14 +957,14 @@ void libmv_getFeature(const struct libmv_Features *libmv_features, int number, d
 
 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNewEmpty(void)
 {
-       libmv::CameraIntrinsics *camera_intrinsics = new libmv::CameraIntrinsics();
+       libmv::CameraIntrinsics *camera_intrinsics = LIBMV_OBJECT_NEW(libmv::CameraIntrinsics);
 
        return (struct libmv_CameraIntrinsics *) camera_intrinsics;
 }
 
 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options)
 {
-       libmv::CameraIntrinsics *camera_intrinsics = new libmv::CameraIntrinsics();
+       libmv::CameraIntrinsics *camera_intrinsics = LIBMV_OBJECT_NEW(libmv::CameraIntrinsics);
 
        cameraIntrinsicsFromOptions(libmv_camera_intrinsics_options, camera_intrinsics);
 
@@ -947,16 +974,15 @@ struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsNew(const libmv_CameraIntri
 struct libmv_CameraIntrinsics *libmv_cameraIntrinsicsCopy(const libmv_CameraIntrinsics *libmvIntrinsics)
 {
        libmv::CameraIntrinsics *orig_intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
-       libmv::CameraIntrinsics *new_intrinsics = new libmv::CameraIntrinsics(*orig_intrinsics);
+       libmv::CameraIntrinsics *new_intrinsics = LIBMV_OBJECT_NEW(libmv::CameraIntrinsics, *orig_intrinsics);
 
        return (struct libmv_CameraIntrinsics *) new_intrinsics;
 }
 
 void libmv_cameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmvIntrinsics)
 {
-       libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
-
-       delete intrinsics;
+       using libmv::CameraIntrinsics;
+       LIBMV_OBJECT_DELETE(libmvIntrinsics, CameraIntrinsics);
 }
 
 void libmv_cameraIntrinsicsUpdate(const libmv_CameraIntrinsicsOptions *libmv_camera_intrinsics_options,
index d5ba2f5bd6858a0299a8b6f70da5a4b59205a24b..aebde0a6425c928ce94d9c1f3a109105eff47998 100644 (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
index dff25f238a7b32c095c3d8ee269b61c04959d3d0..2cffe1a89ef7f6a55c3c01808b7804856ee98838 100644 (file)
@@ -55,9 +55,6 @@ using namespace OCIO_NAMESPACE;
 #  define __func__ __FUNCTION__
 #endif
 
-#define MEM_NEW(type) new(MEM_mallocN(sizeof(type), __func__)) type()
-#define MEM_DELETE(what, type) if (what) { ((type*)(what))->~type(); MEM_freeN(what); } (void)0
-
 static void OCIO_reportError(const char *err)
 {
        std::cerr << "OpenColorIO Error: " << err << std::endl;
@@ -72,7 +69,7 @@ static void OCIO_reportException(Exception &exception)
 
 OCIO_ConstConfigRcPtr *OCIOImpl::getCurrentConfig(void)
 {
-       ConstConfigRcPtr *config = MEM_NEW(ConstConfigRcPtr);
+       ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
 
        try {
                *config = GetCurrentConfig();
@@ -84,7 +81,7 @@ OCIO_ConstConfigRcPtr *OCIOImpl::getCurrentConfig(void)
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(config, ConstConfigRcPtr);
+       OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
 
        return NULL;
 }
@@ -101,7 +98,7 @@ void OCIOImpl::setCurrentConfig(const OCIO_ConstConfigRcPtr *config)
 
 OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromEnv(void)
 {
-       ConstConfigRcPtr *config = MEM_NEW(ConstConfigRcPtr);
+       ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
 
        try {
                *config = Config::CreateFromEnv();
@@ -113,7 +110,7 @@ OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromEnv(void)
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(config, ConstConfigRcPtr);
+       OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
 
        return NULL;
 }
@@ -121,7 +118,7 @@ OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromEnv(void)
 
 OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromFile(const char *filename)
 {
-       ConstConfigRcPtr *config = MEM_NEW(ConstConfigRcPtr);
+       ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
 
        try {
                *config = Config::CreateFromFile(filename);
@@ -133,14 +130,14 @@ OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromFile(const char *filename)
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(config, ConstConfigRcPtr);
+       OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
 
        return NULL;
 }
 
 void OCIOImpl::configRelease(OCIO_ConstConfigRcPtr *config)
 {
-       MEM_DELETE((ConstConfigRcPtr *) config, ConstConfigRcPtr);
+       OBJECT_GUARDED_DELETE((ConstConfigRcPtr *) config, ConstConfigRcPtr);
 }
 
 int OCIOImpl::configGetNumColorSpaces(OCIO_ConstConfigRcPtr *config)
@@ -169,7 +166,7 @@ const char *OCIOImpl::configGetColorSpaceNameByIndex(OCIO_ConstConfigRcPtr *conf
 
 OCIO_ConstColorSpaceRcPtr *OCIOImpl::configGetColorSpace(OCIO_ConstConfigRcPtr *config, const char *name)
 {
-       ConstColorSpaceRcPtr *cs = MEM_NEW(ConstColorSpaceRcPtr);
+       ConstColorSpaceRcPtr *cs = OBJECT_GUARDED_NEW(ConstColorSpaceRcPtr);
 
        try {
                *cs = (*(ConstConfigRcPtr *) config)->getColorSpace(name);
@@ -181,7 +178,7 @@ OCIO_ConstColorSpaceRcPtr *OCIOImpl::configGetColorSpace(OCIO_ConstConfigRcPtr *
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(cs, ConstColorSpaceRcPtr);
+       OBJECT_GUARDED_DELETE(cs, ConstColorSpaceRcPtr);
 
        return NULL;
 }
@@ -308,7 +305,7 @@ const char *OCIOImpl::configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, in
 
 OCIO_ConstLookRcPtr *OCIOImpl::configGetLook(OCIO_ConstConfigRcPtr *config, const char *name)
 {
-       ConstLookRcPtr *look = MEM_NEW(ConstLookRcPtr);
+       ConstLookRcPtr *look = OBJECT_GUARDED_NEW(ConstLookRcPtr);
 
        try {
                *look = (*(ConstConfigRcPtr *) config)->getLook(name);
@@ -320,7 +317,7 @@ OCIO_ConstLookRcPtr *OCIOImpl::configGetLook(OCIO_ConstConfigRcPtr *config, cons
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(look, ConstLookRcPtr);
+       OBJECT_GUARDED_DELETE(look, ConstLookRcPtr);
 
        return NULL;
 }
@@ -332,7 +329,7 @@ const char *OCIOImpl::lookGetProcessSpace(OCIO_ConstLookRcPtr *look)
 
 void OCIOImpl::lookRelease(OCIO_ConstLookRcPtr *look)
 {
-       MEM_DELETE((ConstLookRcPtr *) look, ConstLookRcPtr);
+       OBJECT_GUARDED_DELETE((ConstLookRcPtr *) look, ConstLookRcPtr);
 }
 
 int OCIOImpl::colorSpaceIsInvertible(OCIO_ConstColorSpaceRcPtr *cs_)
@@ -367,12 +364,12 @@ int OCIOImpl::colorSpaceIsData(OCIO_ConstColorSpaceRcPtr *cs)
 
 void OCIOImpl::colorSpaceRelease(OCIO_ConstColorSpaceRcPtr *cs)
 {
-       MEM_DELETE((ConstColorSpaceRcPtr *) cs, ConstColorSpaceRcPtr);
+       OBJECT_GUARDED_DELETE((ConstColorSpaceRcPtr *) cs, ConstColorSpaceRcPtr);
 }
 
 OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessorWithNames(OCIO_ConstConfigRcPtr *config, const char *srcName, const char *dstName)
 {
-       ConstProcessorRcPtr *p = MEM_NEW(ConstProcessorRcPtr);
+       ConstProcessorRcPtr *p = OBJECT_GUARDED_NEW(ConstProcessorRcPtr);
 
        try {
                *p = (*(ConstConfigRcPtr *) config)->getProcessor(srcName, dstName);
@@ -384,14 +381,14 @@ OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessorWithNames(OCIO_ConstConfig
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(p, ConstProcessorRcPtr);
+       OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
 
        return 0;
 }
 
 OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessor(OCIO_ConstConfigRcPtr *config, OCIO_ConstTransformRcPtr *transform)
 {
-       ConstProcessorRcPtr *p = MEM_NEW(ConstProcessorRcPtr);
+       ConstProcessorRcPtr *p = OBJECT_GUARDED_NEW(ConstProcessorRcPtr);
 
        try {
                *p = (*(ConstConfigRcPtr *) config)->getProcessor(*(ConstTransformRcPtr *) transform);
@@ -403,7 +400,7 @@ OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessor(OCIO_ConstConfigRcPtr *co
                OCIO_reportException(exception);
        }
 
-       MEM_DELETE(p, ConstProcessorRcPtr);
+       OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
 
        return NULL;
 }
@@ -482,7 +479,7 @@ void OCIOImpl::processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *processor,
 
 void OCIOImpl::processorRelease(OCIO_ConstProcessorRcPtr *p)
 {
-       MEM_DELETE(p, ConstProcessorRcPtr);
+       OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
 }
 
 const char *OCIOImpl::colorSpaceGetName(OCIO_ConstColorSpaceRcPtr *cs)
@@ -502,7 +499,7 @@ const char *OCIOImpl::colorSpaceGetFamily(OCIO_ConstColorSpaceRcPtr *cs)
 
 OCIO_DisplayTransformRcPtr *OCIOImpl::createDisplayTransform(void)
 {
-       DisplayTransformRcPtr *dt = MEM_NEW(DisplayTransformRcPtr);
+       DisplayTransformRcPtr *dt = OBJECT_GUARDED_NEW(DisplayTransformRcPtr);
 
        *dt = DisplayTransform::Create();
 
@@ -546,7 +543,7 @@ void OCIOImpl::displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransformRcPt
 
 void OCIOImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr *dt)
 {
-       MEM_DELETE((DisplayTransformRcPtr *) dt, DisplayTransformRcPtr);
+       OBJECT_GUARDED_DELETE((DisplayTransformRcPtr *) dt, DisplayTransformRcPtr);
 }
 
 OCIO_PackedImageDesc *OCIOImpl::createOCIO_PackedImageDesc(float *data, long width, long height, long numChannels,
@@ -567,12 +564,12 @@ OCIO_PackedImageDesc *OCIOImpl::createOCIO_PackedImageDesc(float *data, long wid
 
 void OCIOImpl::OCIO_PackedImageDescRelease(OCIO_PackedImageDesc* id)
 {
-       MEM_DELETE((PackedImageDesc *) id, PackedImageDesc);
+       OBJECT_GUARDED_DELETE((PackedImageDesc *) id, PackedImageDesc);
 }
 
 OCIO_ExponentTransformRcPtr *OCIOImpl::createExponentTransform(void)
 {
-       ExponentTransformRcPtr *et = MEM_NEW(ExponentTransformRcPtr);
+       ExponentTransformRcPtr *et = OBJECT_GUARDED_NEW(ExponentTransformRcPtr);
 
        *et = ExponentTransform::Create();
 
@@ -586,12 +583,12 @@ void OCIOImpl::exponentTransformSetValue(OCIO_ExponentTransformRcPtr *et, const
 
 void OCIOImpl::exponentTransformRelease(OCIO_ExponentTransformRcPtr *et)
 {
-       MEM_DELETE((ExponentTransformRcPtr *) et, ExponentTransformRcPtr);
+       OBJECT_GUARDED_DELETE((ExponentTransformRcPtr *) et, ExponentTransformRcPtr);
 }
 
 OCIO_MatrixTransformRcPtr *OCIOImpl::createMatrixTransform(void)
 {
-       MatrixTransformRcPtr *mt = MEM_NEW(MatrixTransformRcPtr);
+       MatrixTransformRcPtr *mt = OBJECT_GUARDED_NEW(MatrixTransformRcPtr);
 
        *mt = MatrixTransform::Create();
 
@@ -605,7 +602,7 @@ void OCIOImpl::matrixTransformSetValue(OCIO_MatrixTransformRcPtr *mt, const floa
 
 void OCIOImpl::matrixTransformRelease(OCIO_MatrixTransformRcPtr *mt)
 {
-       MEM_DELETE((MatrixTransformRcPtr *) mt, MatrixTransformRcPtr);
+       OBJECT_GUARDED_DELETE((MatrixTransformRcPtr *) mt, MatrixTransformRcPtr);
 }
 
 void OCIOImpl::matrixTransformScale(float *m44, float *offset4, const float *scale4f)