home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: new returns address it already returned!
- Message-ID: <1992Dec11.220827.6197@microsoft.com>
- Date: 11 Dec 92 22:08:27 GMT
- Organization: Microsoft Corporation
- References: <Bz24B3.62A@news.cso.uiuc.edu>
- Lines: 29
-
- In article <Bz24B3.62A@news.cso.uiuc.edu> dmd39855@uxa.cso.uiuc.edu (Daniel DuBois) writes:
- |Anybody know what the heck is going on? Why in heck would new return the
- |same address?
-
- Two common ways for this to happen are:
-
- 1) A delete has been called on the prior allocation, freeing the block to
- be reused by new.
-
- 2) A delete has been called incorrectly on somw prior allocation, corrupting
- the heap, leading new to think the block in question is free to be reused by
- new.
-
- Common ways to corrupt the heap include:
-
- * Using polymorphism and news/deletes without declaring virtual destructors.
-
- * Mixing up new/delete with new[n]/delete[]
-
- * writing off the end of an allocation.
-
- As a test, I suggest if at all possible start by commenting out ALL of
- the delete statements your program uses. Not some, ALL of them. This
- is only possible to do if your program makes reasonably bounded use of
- heap. If you can do this, and if doing so causes your bug to go away,
- then your error is in one or more of the delete statements [or side-effects
- they cause] The question then simply becomes which one[s] to fix.
- Note that MFC has a debugging new/delete option that is frequently useful
- in tracking down allocation problems.
-