malloc: override 'new' and 'delete' globally
authorBrian Norris <banorris@uci.edu>
Thu, 5 Apr 2012 02:41:46 +0000 (19:41 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 5 Apr 2012 17:05:30 +0000 (10:05 -0700)
Not sure if this is correct...

Q: do we also need to overload new[] and delete[]?

malloc.c

index 196be43..82fdd04 100644 (file)
--- a/malloc.c
+++ b/malloc.c
@@ -6,6 +6,7 @@
 #endif
 
 #include <dlfcn.h>
+#include <new>
 
 static void * (*real_malloc)(size_t) = NULL;
 static void (*real_free)(void *ptr) = NULL;
@@ -36,3 +37,13 @@ void myFree(void *ptr)
 
        real_free(ptr);
 }
+
+void * operator new(size_t size)
+{
+       return myMalloc(size);
+}
+
+void operator delete(void *p)
+{
+       myFree(p);
+}