balancing free() and malloc()

Dale Worley worley at compass.com
Tue Jun 25 01:01:18 AEST 1991


To prevent memory leaks and detect invalid uses of free, I once wrote
wrappers for malloc and free that kept all allocated blocks on a
doubly-linked list.  At the end of processing, the list should be
empty.  Also, free can check that the block is properly linked in (the
blocks pointed to by the forward and backward pointers have to point
back to the original block).  You can also put guard words before and
after the section returned to the user to make sure he isn't writing
off the end of the block.  That code saved me a lot of time hunting
for bugs.

Dale Worley		Compass, Inc.			worley at compass.com
--
If you can't drink a lobbyist's whisky, take his money, sleep with his
women and still vote against him in the morning, you don't belong in
politics.	-- Speaker of the California Assembly Jesse Unruh



More information about the Comp.lang.c mailing list