diff options
author | Dwight <dmerriman@gmail.com> | 2008-07-17 13:42:20 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-07-17 13:42:20 -0400 |
commit | c3adb4946fd99ff8a76fc1abb0fabbbae2254c80 (patch) | |
tree | b7f211968e9f216eb5a984bb492c76ef5f7bcc1a | |
parent | 2612fa547b8c7a83d96d252e2db4cc36f93b7fd8 (diff) | |
download | mongo-c3adb4946fd99ff8a76fc1abb0fabbbae2254c80.tar.gz |
check for out of memory
-rw-r--r-- | db/db.cpp | 4 | ||||
-rw-r--r-- | stdafx.h | 20 | ||||
-rw-r--r-- | util/log.h | 1 |
3 files changed, 21 insertions, 4 deletions
diff --git a/db/db.cpp b/db/db.cpp index aba19dd06e1..d4aa4ce04be 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -930,8 +930,8 @@ int main(int argc, char* argv[], char *envp[] ) //#endif #undef exit -void dbexit(int rc) { - cout << " dbexit: flushing op log and files" << endl; +void dbexit(int rc, const char *why) { + cout << " dbexit: " << why << "; flushing op log and files" << endl; flushOpLog(); /* must do this before unmapping mem or you may get a seg fault */ @@ -11,6 +11,25 @@ const bool debug=true; const bool debug=false; #endif +#include <memory> + +extern void dbexit(int returnCode, const char *whyMsg = ""); + +inline void * ourmalloc(size_t size) { + void *x = malloc(size); + if( x == 0 ) dbexit(42, "malloc fails"); + return x; +} + +inline void * ourrealloc(void *ptr, size_t size) { + void *x = realloc(ptr, size); + if( x == 0 ) dbexit(43, "realloc fails"); + return x; +} + +#define malloc ourmalloc +#define realloc ourrealloc + #include "targetver.h" //#include "assert.h" @@ -126,7 +145,6 @@ inline void our_debug_free(void *p) { #define free our_debug_free #endif -void dbexit(int resultcode); #define exit dbexit #undef yassert diff --git a/util/log.h b/util/log.h index d4496de02c5..9d7df6ec9b4 100644 --- a/util/log.h +++ b/util/log.h @@ -53,4 +53,3 @@ extern Logstream logstream; inline Logstream& problem() { return logstream.prolog(); } #define cout logstream - |