Path: utzoo!attcan!uunet!amsdsg!jeff From: jeff@amsdsg.UUCP (Jeff Barr) Newsgroups: comp.lang.c Subject: Re: Tracking memory leaks.. Summary: Tracking Memory Use Message-ID: <164@amsdsg.UUCP> Date: 9 Sep 88 12:52:24 GMT References: <3950011@eecs.nwu.edu> Organization: AMS Departmental Systems Group, Arlington, VA Lines: 23 In article <3950011@eecs.nwu.edu>, naim@eecs.nwu.edu (Naim Abdullah) writes: > I want to check sections of a big program for memory leaks. My basic > strategy was to define functions xmalloc() and xfree() that would keep > track of the amount allocated, and to see if the amount went down to > zero where it should (I wanted to use "#define malloc xmalloc" in the > main header file to replace occurrences of malloc() and free()). > > The problem with this scheme is that I don't know how much space free() > will actually free. You can allocate space for an extra 'int' in xmalloc, store the size yourself at the beginning of the allocated block (being sure to return a pointer PAST the 'int'), and then retrieve it in xfree. Jeff +---------------------------------------------------------+ | Jeff Barr AMS-DSG uunet!amsdsg!jeff 800-832-8668 | +---------------------------------------------------------+ -- Jeff +---------------------------------------------------------+ | Jeff Barr AMS-DSG uunet!amsdsg!jeff 800-832-8668 | +---------------------------------------------------------+