/ Check-in [58f7ca29]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a compiler warning and an after-OOM memory leak.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | orderby-planning
Files: files | file ages | folders
SHA1: 58f7ca29303c280229f86d01f418e1de5f5aebba
User & Date: drh 2014-03-28 19:47:19
Context
2014-04-24
15:06
Reopen the orderby-planning branch and merge in the latest trunk enhancements and fixes. check-in: 6077ddcd user: drh tags: orderby-planning
2014-03-28
19:47
Fix a compiler warning and an after-OOM memory leak. check-in: 58f7ca29 user: drh tags: orderby-planning
18:35
Merge the latest changes from trunk. check-in: 3047a25f user: drh tags: orderby-planning
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/vdbesort.c.

   955    955         int nNew = pSorter->nMemory * 2;
   956    956         while( nNew < nMin ) nNew = nNew*2;
   957    957         if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
   958    958         if( nNew < nMin ) nNew = nMin;
   959    959   
   960    960         aNew = sqlite3Realloc(pSorter->aMemory, nNew);
   961    961         if( !aNew ) return SQLITE_NOMEM;
   962         -      pSorter->pRecord = aNew + ((u8*)pSorter->pRecord - pSorter->aMemory);
          962  +      pSorter->pRecord = (SorterRecord*)
          963  +           (aNew + ((u8*)pSorter->pRecord - pSorter->aMemory));
   963    964         pSorter->aMemory = aNew;
   964    965         pSorter->nMemory = nNew;
   965    966       }
   966    967   
   967    968       pNew = (SorterRecord*)&pSorter->aMemory[pSorter->iMemory];
   968    969       pSorter->iMemory += ROUND8(nReq);
   969    970       pNew->u.iNext = (u8*)(pSorter->pRecord) - pSorter->aMemory;
................................................................................
  1048   1049     while( N<nIter ) N += N;
  1049   1050     nByte = N * (sizeof(int) + sizeof(VdbeSorterIter));
  1050   1051     pSorter->aIter = (VdbeSorterIter *)sqlite3DbMallocZero(db, nByte);
  1051   1052     if( !pSorter->aIter ) return SQLITE_NOMEM;
  1052   1053     pSorter->aTree = (int *)&pSorter->aIter[N];
  1053   1054     pSorter->nTree = N;
  1054   1055   
  1055         -  do {
         1056  +  while(1){
  1056   1057       int iNew;                     /* Index of new, merged, PMA */
  1057   1058   
  1058   1059       for(iNew=0; 
  1059   1060           rc==SQLITE_OK && iNew*SORTER_MAX_MERGE_COUNT<pSorter->nPMA; 
  1060   1061           iNew++
  1061   1062       ){
  1062   1063         int rc2;                    /* Return code from fileWriterFinish() */
................................................................................
  1101   1102             fileWriterWrite(&writer, pIter->aKey, pIter->nKey);
  1102   1103             rc = sqlite3VdbeSorterNext(db, pCsr, &bEof);
  1103   1104           }
  1104   1105           rc2 = fileWriterFinish(db, &writer, &iWrite2);
  1105   1106           if( rc==SQLITE_OK ) rc = rc2;
  1106   1107         }
  1107   1108       }
         1109  +    if( rc ) break;
  1108   1110   
  1109   1111       if( pSorter->nPMA<=SORTER_MAX_MERGE_COUNT ){
  1110   1112         break;
  1111   1113       }else{
  1112   1114         sqlite3_file *pTmp = pSorter->pTemp1;
  1113   1115         pSorter->nPMA = iNew;
  1114   1116         pSorter->pTemp1 = pTemp2;
  1115   1117         pTemp2 = pTmp;
  1116   1118         pSorter->iWriteOff = iWrite2;
  1117   1119         pSorter->iReadOff = 0;
  1118   1120         iWrite2 = 0;
  1119   1121       }
  1120         -  }while( rc==SQLITE_OK );
         1122  +  }
  1121   1123   
  1122   1124     if( pTemp2 ){
  1123   1125       sqlite3OsCloseFree(pTemp2);
  1124   1126     }
  1125   1127     *pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
  1126   1128     return rc;
  1127   1129   }