Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!compass!worley From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.c Subject: Re: balancing free() and malloc() Message-ID: Date: 24 Jun 91 15:01:18 GMT References: <1991Jun22.173609.28393@cbnewsl.att.com> Sender: root@compass.com Distribution: na Organization: Compass, Inc., Wakefield, MA, U.S.A. Lines: 15 In-reply-to: rl@cbnewsl.att.com's message of 22 Jun 91 17:36:09 GMT 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@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