   malloc sporatically returning null in debug mode?
  Hi everybody,I'm doing some development in C using Microsoft Visual C++ Express and have found that from time to time in my app malloc will return null. I re-routed all my malloc calls to a new "my_malloc" that just counted up the total malloc'd space and found this was happening after only allocating 11MB! I then re-wrote my_malloc to say:m = malloc(size);while (!m)   m = malloc(size);and everything works again! Does anybody know why malloc would return null but then give a valid pointer if called immediately afterward? (This is only seen in debug mode)Thanks in advance!-Chris   
  That sounds really odd. Can you produce a minimal program for us to that demonstrates the behaviour?   ;  That does sound odd. I can't see why it'd be happening unless you're corrupting the heap (e.g. writing to a freed object or outside of the bounds of an allocated array), or possibly if you're trying to use the single-threaded runtime in a multi-threaded  application.You might try turning on some of the debug allocator checks with _CrtSetDbgFlag or intersperse the rest of your program with calls to _CrtCheckMemory.;  Oh.. Stupid! I was overrunning an array. Go figure. Interesting that it would cause that kind of behavior though. I wonder why...   ;  Thanks for the replies!   ;  Because you were overwriting the data your memory allocator uses to manage blocks.   