caw@jolnet.ORPK.IL.US (Chris Wichura) (12/27/89)
I have discovered a bug in v39 of arp.library. It has to do with the ArpAlloc() function returning an incorrect tracker node in A1. If one then calls FreeTrackedItem(tracker) you get visited by the GURU. I looked at the code with MetaScope and found that ArpAlloc() `cheats' by allocating a TRAK_AAMEM node instead of a TRAK_MEM. It does a DOSAllocMem() call of the size requested plus 12 bytes. It then puts the tracker node at the base, adds 12 bytes to the tracker node and returns that as the data area. Now, the thing is is that the pointer to the returned data node __IS__ the correct address to call FreeTrackedItem() with because 12 bytes up from the base of a TrackerResoure is the DefaultTracker structure that FreeTrackedItem() wants. Now, my question is was this put in as a `feature'? The docs seem to indicate that one should still use the FreeTrackedItem() method. However, it would seem to me that maybe the folks at ARP made this a `short-cut' so that one wouldn't have to track a whole bunch of DefaultTracker pointers along with the mem pointers as AllocMem() could easily be one of the most used functions in the library. And the fact that AllocMem() was #pragma'ed in the Lattice include files seems to suggest this idea as well. Even if this is true, though, returning an invalid a1 pointer is inexcusable, especially when the docs say you need that pointer to free the resourece. My application checks for arp v39 in the OpenLibrary() call so I am not too woried about old versions of arp being a problem. Howevere, when (or if), a new version of arp.library comes along what will happen to my code then? Currently I have been doing the FreeTrackedItem() call with the pointer to the returned memory area as this works. But will it work in v40? And will v40 correctly set A1 in this function? Since all the other tracker functions use GetTracker() they return the correct pointer for a FreeTrackedItem() call. If I were to be really compatible with v40 and up should I use ArpAllocMem(size, flags) for the one-shot memory I grab? Christoper A. Wichura (u12401@uicvm.uic.edu -- my home account)