|
From: Andreas S. <ma...@cy...> - 2009-05-18 17:33:52
|
On Monday 18 May 2009 19:19:01 Marcus Baker wrote: > Hi... Hello, > > I'm trying to avoid spraying a whole bunch of NULL checks everywhere. I > propose that a malloc failure in the CGreen code itself is fatal and we > jump straight out of our own version of malloc()/realloc(). well, cgreen is a library and a library should never call exit(). It should report a fatal error and the application which is using the cgreen library should call exit(). The test developer should be able to cleanup his own things! > 1) In the master process, something is really wrong if malloc() fails. > It means the test suite and CUT has been grabbing memory and locking it > into RAM. We print the name of the test suite (so the user knows how far > they got) and stop the test run. And go back to the application :) > > 2) In a test process, we just bomb the test. There is a problem keeping > lint and valgrind happy in this case. In bombing out, we have to clean > everything up. I propose that we use our own versions of malloc() and > free() when inside tests. Either the exit handler or a longjmp() can be > used to trigger the cleanup. Cleanup the memory and return a FATAL error to the test application. Use functions with return values instead of void. > I like the idea of registering unallocated blocks and cleaning them up > en masse. It gets rid of free() calls in the code and is safer. Have you ever looked at talloc? Cheers, -- andreas |