Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!apple.com!rpd From: rpd@apple.com (Rick Daley) Newsgroups: comp.sys.mac.programmer Subject: Re: Stale Pointers Message-ID: <2551@internal.Apple.COM> Date: 28 Jun 89 21:53:41 GMT References: <2394@ur-cc.UUCP> Sender: usenet@Apple.COM Distribution: usa Organization: Apple Computer Lines: 21 In article <2394@ur-cc.UUCP> giaccone@uhura.cc.rochester.edu (Tony Giaccone) writes: > (**myImage).rasI_image = (SIPtr) NewPtr(size); > if ((**myImage).rasI_image == NULL) { ... > it seems odd that Lightspeed C should do part of the dereference > before the call, and the other part after the call. What do you think? This is a nasty problem that bites people every once in a while. However, C does not define the order of evaluation in an assignment. Your code might work with some compilers, but it's not safe. The best thing to do is to use a temporary variable: tmp = (SIPtr) NewPtr(size); if (((**myImage).rasI_image = tmp)== NULL) { This is better than HLocking the block because it avoids fragmenting the heap. The reason you saw the bug is that the Memory Manager had to compact the heap to make room for the new block. If you lock the relocatable block, you might cause the NewPtr to fail. Rick Daley rpd@apple.com