If I call this function exactly 19 times it will always
crash on the 19th with an access low memory error
and it will crash on this line
strArray[recordindex] = MemPtrNew(StrLen(p) + 1);
I have tried usinf the debugger but can not see what is wrong
Am I failing to release some memory on exit of the function





search_database()
{
    Char *p;
        Char **strArray = NULL; 
        Char* strLines = NULL;
        Err err;
        UInt16 index = 0, recordindex = 0, nRecordIndex = 0;
        FormPtr form1;
        ListType *lsp1;
        MemHandle Rh;
        
        
        form1 = FrmGetActiveForm(); // get active form
                
        err = Open(); // routine to open database
    if(!err)
        {
         lsp1 = FrmGetObjectPtr(form1, FrmGetObjectIndex(form1, frmList1)); // 
get id of list control
         nRecordIndex = DmNumRecords(dbPtr); // number of records
     strArray = MemPtrNew(nRecordIndex * sizeof(Char *));

         for(index =0; index < nRecordIndex; index++) // lets index through 
database
          {
           Rh = DmQueryRecord(dbPtr, index); // lets query each record
           p = (Char *) MemHandleLock(Rh); // lets lock each record
       if( 0 == StrNCaselessCompare( letter, p, 1) ) //compare first letter of 
first field
            {
            
                 strArray[recordindex] = MemPtrNew(StrLen(p) + 1);
         StrCopy(strArray[recordindex], p);
         recordindex++; 
                
            }
           MemHandleUnlock(Rh); // unlock each record 
          }
         LstSetListChoices(lsp1,strArray,recordindex); 
     LstDrawList( lsp1 );
         err = CloseDB(); 
        }
        return true;
}

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

Reply via email to