> Is a free handle an invalid handle? A freed handle?

It's the latter.  It's a handle that has been passed to MemHandleFree.

> Doesn't DmGetRecord() return a handle?

It does it if has one to give. But imagine the following (buggy) code:

    recordH = DmGetRecord(dbToUse, indexToGet);
    MemHandleFree (recordH); /* Oops! Need to call DmDetachRecord first! */

    /* lot's of other stuff */

    recordH = DmGetRecord(dbToUse, indexToGet);
    if (recordH == NULL)
        ErrDisplay("Can retrieve record");
    recText = (Char*)MemHandleLock(recordH);

Under this scenario, the second call to DmGetRecord will return a handle to a
chunk of memory that has been freed.

-- Keith







[EMAIL PROTECTED] on 07/06/2000 01:13:45 AM

Please respond to "Palm Developer Forum" <[EMAIL PROTECTED]>

Sent by:  [EMAIL PROTECTED]


To:   "Palm Developer Forum" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/US/PALM)
Subject:  Free handle, what is it?



Hi all,
I need help debugging this little code snippet.

/*global*/ DmOpenRef     dbToUse;

void static MyFunction();
 MemHandle     recordH;
 Char               *recText;
{
    recordH = DmGetRecord(dbToUse, indexToGet);
    if (recordH == NULL)
        ErrDisplay("Can retrieve record");
    recText = (Char*)MemHandleLock(recordH);
}



dbToUse has been opened by
DmOpenDatabaseByTypeCreator(MenuProtoUserDBType, CreatorID, mode);
elsewhere. I'm pretty sure the dbToUse is opened for reading, I've even
checked it with

 error = DmOpenDatabaseInfo(dbToUse, &dbID, &openCount, &mode, &cardNo,
&resDB);
 ErrFatalDisplayIf(error, "Database not opened");

The problem is whenever I try to lock recordH with
MemHandleLock(recordH); I get "MemoryMgrNew.c, Line:4177, Free handle"
on the log window.
recText would then point to some invalid address space.

Is a free handle an invalid handle? A freed handle? Doesn't
DmGetRecord() return a handle? Or do I have to explicitly use a
recordH=MemHandleNew(x)? But I wouldn't know how much memory to assign
for DmGetRecord.

Any help would be greatly appreciated. Thanks!!

Wee Meng CHONG







--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/tech/support/forums/





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to