/ Check-in [6a9c4a3e]
Login

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

Overview
Comment:Enhance ability to debug out-of-memory errors.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | noMemBkpt
Files: files | file ages | folders
SHA1: 6a9c4a3ebfb7cc0738ef6634440ccab44a21ff28
User & Date: mistachkin 2016-02-13 23:43:46
Context
2016-02-14
00:14
Update a comment. Closed-Leaf check-in: e9753d9a user: mistachkin tags: noMemBkpt
2016-02-13
23:43
Enhance ability to debug out-of-memory errors. check-in: 6a9c4a3e user: mistachkin tags: noMemBkpt
18:54
Provide Sqlite3_SafeInit() and Sqlite3_SafeUnload() entry points on the TCL interface, but have the always return TCL_ERROR, because the non-standard TCL builds on Macs require this. check-in: 37ec3015 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1669   1669     char *zSql;                   /* Text of the SQL statement */
  1670   1670     Index *pPrevIdx = 0;          /* Previous index in the loop */
  1671   1671     IndexSample *pSample;         /* A slot in pIdx->aSample[] */
  1672   1672   
  1673   1673     assert( db->lookaside.bDisable );
  1674   1674     zSql = sqlite3MPrintf(db, zSql1, zDb);
  1675   1675     if( !zSql ){
  1676         -    return SQLITE_NOMEM;
         1676  +    return SQLITE_NOMEM_BKPT;
  1677   1677     }
  1678   1678     rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
  1679   1679     sqlite3DbFree(db, zSql);
  1680   1680     if( rc ) return rc;
  1681   1681   
  1682   1682     while( sqlite3_step(pStmt)==SQLITE_ROW ){
  1683   1683       int nIdxCol = 1;              /* Number of columns in stat4 records */
................................................................................
  1709   1709       nByte = sizeof(IndexSample) * nSample;
  1710   1710       nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
  1711   1711       nByte += nIdxCol * sizeof(tRowcnt);     /* Space for Index.aAvgEq[] */
  1712   1712   
  1713   1713       pIdx->aSample = sqlite3DbMallocZero(db, nByte);
  1714   1714       if( pIdx->aSample==0 ){
  1715   1715         sqlite3_finalize(pStmt);
  1716         -      return SQLITE_NOMEM;
         1716  +      return SQLITE_NOMEM_BKPT;
  1717   1717       }
  1718   1718       pSpace = (tRowcnt*)&pIdx->aSample[nSample];
  1719   1719       pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
  1720   1720       for(i=0; i<nSample; i++){
  1721   1721         pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
  1722   1722         pIdx->aSample[i].anLt = pSpace; pSpace += nIdxCol;
  1723   1723         pIdx->aSample[i].anDLt = pSpace; pSpace += nIdxCol;
................................................................................
  1725   1725       assert( ((u8*)pSpace)-nByte==(u8*)(pIdx->aSample) );
  1726   1726     }
  1727   1727     rc = sqlite3_finalize(pStmt);
  1728   1728     if( rc ) return rc;
  1729   1729   
  1730   1730     zSql = sqlite3MPrintf(db, zSql2, zDb);
  1731   1731     if( !zSql ){
  1732         -    return SQLITE_NOMEM;
         1732  +    return SQLITE_NOMEM_BKPT;
  1733   1733     }
  1734   1734     rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
  1735   1735     sqlite3DbFree(db, zSql);
  1736   1736     if( rc ) return rc;
  1737   1737   
  1738   1738     while( sqlite3_step(pStmt)==SQLITE_ROW ){
  1739   1739       char *zIndex;                 /* Index name */
................................................................................
  1763   1763       ** end of the allocated buffer before it realizes it is dealing with
  1764   1764       ** a corrupt record. Adding the two 0x00 bytes prevents this from causing
  1765   1765       ** a buffer overread.  */
  1766   1766       pSample->n = sqlite3_column_bytes(pStmt, 4);
  1767   1767       pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
  1768   1768       if( pSample->p==0 ){
  1769   1769         sqlite3_finalize(pStmt);
  1770         -      return SQLITE_NOMEM;
         1770  +      return SQLITE_NOMEM_BKPT;
  1771   1771       }
  1772   1772       memcpy(pSample->p, sqlite3_column_blob(pStmt, 4), pSample->n);
  1773   1773       pIdx->nSample++;
  1774   1774     }
  1775   1775     rc = sqlite3_finalize(pStmt);
  1776   1776     if( rc==SQLITE_OK ) initAvgEq(pPrevIdx);
  1777   1777     return rc;
................................................................................
  1852   1852       return SQLITE_ERROR;
  1853   1853     }
  1854   1854   
  1855   1855     /* Load new statistics out of the sqlite_stat1 table */
  1856   1856     zSql = sqlite3MPrintf(db, 
  1857   1857         "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
  1858   1858     if( zSql==0 ){
  1859         -    rc = SQLITE_NOMEM;
         1859  +    rc = SQLITE_NOMEM_BKPT;
  1860   1860     }else{
  1861   1861       rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
  1862   1862       sqlite3DbFree(db, zSql);
  1863   1863     }
  1864   1864   
  1865   1865   
  1866   1866     /* Load the statistics from the sqlite_stat4 table. */

Changes to src/attach.c.

   140    140     if( rc==SQLITE_CONSTRAINT ){
   141    141       rc = SQLITE_ERROR;
   142    142       zErrDyn = sqlite3MPrintf(db, "database is already attached");
   143    143     }else if( rc==SQLITE_OK ){
   144    144       Pager *pPager;
   145    145       aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
   146    146       if( !aNew->pSchema ){
   147         -      rc = SQLITE_NOMEM;
          147  +      rc = SQLITE_NOMEM_BKPT;
   148    148       }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
   149    149         zErrDyn = sqlite3MPrintf(db, 
   150    150           "attached databases must use the same text encoding as main database");
   151    151         rc = SQLITE_ERROR;
   152    152       }
   153    153       sqlite3BtreeEnter(aNew->pBt);
   154    154       pPager = sqlite3BtreePager(aNew->pBt);
................................................................................
   160    160                         PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
   161    161   #endif
   162    162       sqlite3BtreeLeave(aNew->pBt);
   163    163     }
   164    164     aNew->safety_level = 3;
   165    165     aNew->zName = sqlite3DbStrDup(db, zName);
   166    166     if( rc==SQLITE_OK && aNew->zName==0 ){
   167         -    rc = SQLITE_NOMEM;
          167  +    rc = SQLITE_NOMEM_BKPT;
   168    168     }
   169    169   
   170    170   
   171    171   #ifdef SQLITE_HAS_CODEC
   172    172     if( rc==SQLITE_OK ){
   173    173       extern int sqlite3CodecAttach(sqlite3*, int, const void*, int);
   174    174       extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);

Changes to src/backup.c.

    84     84   
    85     85     if( i==1 ){
    86     86       Parse *pParse;
    87     87       int rc = 0;
    88     88       pParse = sqlite3StackAllocZero(pErrorDb, sizeof(*pParse));
    89     89       if( pParse==0 ){
    90     90         sqlite3ErrorWithMsg(pErrorDb, SQLITE_NOMEM, "out of memory");
    91         -      rc = SQLITE_NOMEM;
           91  +      rc = SQLITE_NOMEM_BKPT;
    92     92       }else{
    93     93         pParse->db = pDb;
    94     94         if( sqlite3OpenTempDatabase(pParse) ){
    95     95           sqlite3ErrorWithMsg(pErrorDb, pParse->rc, "%s", pParse->zErrMsg);
    96     96           rc = SQLITE_ERROR;
    97     97         }
    98     98         sqlite3DbFree(pErrorDb, pParse->zErrMsg);
................................................................................
   178    178     }else {
   179    179       /* Allocate space for a new sqlite3_backup object...
   180    180       ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
   181    181       ** call to sqlite3_backup_init() and is destroyed by a call to
   182    182       ** sqlite3_backup_finish(). */
   183    183       p = (sqlite3_backup *)sqlite3MallocZero(sizeof(sqlite3_backup));
   184    184       if( !p ){
   185         -      sqlite3Error(pDestDb, SQLITE_NOMEM);
          185  +      sqlite3Error(pDestDb, SQLITE_NOMEM_BKPT);
   186    186       }
   187    187     }
   188    188   
   189    189     /* If the allocation succeeded, populate the new object. */
   190    190     if( p ){
   191    191       p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
   192    192       p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
................................................................................
   577    577         TESTONLY( int rc2 );
   578    578         TESTONLY( rc2  = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
   579    579         TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
   580    580         assert( rc2==SQLITE_OK );
   581    581       }
   582    582     
   583    583       if( rc==SQLITE_IOERR_NOMEM ){
   584         -      rc = SQLITE_NOMEM;
          584  +      rc = SQLITE_NOMEM_BKPT;
   585    585       }
   586    586       p->rc = rc;
   587    587     }
   588    588     if( p->pDestDb ){
   589    589       sqlite3_mutex_leave(p->pDestDb->mutex);
   590    590     }
   591    591     sqlite3BtreeLeave(p->pSrc);

Changes to src/bitvec.c.

   173    173     assert( i<=p->iSize );
   174    174     i--;
   175    175     while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
   176    176       u32 bin = i/p->iDivisor;
   177    177       i = i%p->iDivisor;
   178    178       if( p->u.apSub[bin]==0 ){
   179    179         p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
   180         -      if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
          180  +      if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM_BKPT;
   181    181       }
   182    182       p = p->u.apSub[bin];
   183    183     }
   184    184     if( p->iSize<=BITVEC_NBIT ){
   185    185       p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1));
   186    186       return SQLITE_OK;
   187    187     }
................................................................................
   208    208     /* make our hash too "full".  */
   209    209   bitvec_set_rehash:
   210    210     if( p->nSet>=BITVEC_MXHASH ){
   211    211       unsigned int j;
   212    212       int rc;
   213    213       u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
   214    214       if( aiValues==0 ){
   215         -      return SQLITE_NOMEM;
          215  +      return SQLITE_NOMEM_BKPT;
   216    216       }else{
   217    217         memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash));
   218    218         memset(p->u.apSub, 0, sizeof(p->u.apSub));
   219    219         p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
   220    220         rc = sqlite3BitvecSet(p, i);
   221    221         for(j=0; j<BITVEC_NINT; j++){
   222    222           if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);

Changes to src/btree.c.

   346    346   
   347    347     /* If the above search did not find a BtLock struct associating Btree p
   348    348     ** with table iTable, allocate one and link it into the list.
   349    349     */
   350    350     if( !pLock ){
   351    351       pLock = (BtLock *)sqlite3MallocZero(sizeof(BtLock));
   352    352       if( !pLock ){
   353         -      return SQLITE_NOMEM;
          353  +      return SQLITE_NOMEM_BKPT;
   354    354       }
   355    355       pLock->iTable = iTable;
   356    356       pLock->pBtree = p;
   357    357       pLock->pNext = pBt->pLock;
   358    358       pBt->pLock = pLock;
   359    359     }
   360    360   
................................................................................
   549    549   */
   550    550   static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
   551    551     int rc = SQLITE_OK;
   552    552     if( !pBt->pHasContent ){
   553    553       assert( pgno<=pBt->nPage );
   554    554       pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
   555    555       if( !pBt->pHasContent ){
   556         -      rc = SQLITE_NOMEM;
          556  +      rc = SQLITE_NOMEM_BKPT;
   557    557       }
   558    558     }
   559    559     if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
   560    560       rc = sqlite3BitvecSet(pBt->pHasContent, pgno);
   561    561     }
   562    562     return rc;
   563    563   }
................................................................................
   628    628         rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
   629    629         if( rc==SQLITE_OK ){
   630    630           pCur->pKey = pKey;
   631    631         }else{
   632    632           sqlite3_free(pKey);
   633    633         }
   634    634       }else{
   635         -      rc = SQLITE_NOMEM;
          635  +      rc = SQLITE_NOMEM_BKPT;
   636    636       }
   637    637     }
   638    638     assert( !pCur->curIntKey || !pCur->pKey );
   639    639     return rc;
   640    640   }
   641    641   
   642    642   /*
................................................................................
   760    760     char *pFree = 0;
   761    761   
   762    762     if( pKey ){
   763    763       assert( nKey==(i64)(int)nKey );
   764    764       pIdxKey = sqlite3VdbeAllocUnpackedRecord(
   765    765           pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
   766    766       );
   767         -    if( pIdxKey==0 ) return SQLITE_NOMEM;
          767  +    if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
   768    768       sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
   769    769       if( pIdxKey->nField==0 ){
   770    770         sqlite3DbFree(pCur->pKeyInfo->db, pFree);
   771    771         return SQLITE_CORRUPT_BKPT;
   772    772       }
   773    773     }else{
   774    774       pIdxKey = 0;
................................................................................
  2172   2172       flags |= BTREE_MEMORY;
  2173   2173     }
  2174   2174     if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
  2175   2175       vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
  2176   2176     }
  2177   2177     p = sqlite3MallocZero(sizeof(Btree));
  2178   2178     if( !p ){
  2179         -    return SQLITE_NOMEM;
         2179  +    return SQLITE_NOMEM_BKPT;
  2180   2180     }
  2181   2181     p->inTrans = TRANS_NONE;
  2182   2182     p->db = db;
  2183   2183   #ifndef SQLITE_OMIT_SHARED_CACHE
  2184   2184     p->lock.pBtree = p;
  2185   2185     p->lock.iTable = 1;
  2186   2186   #endif
................................................................................
  2196   2196         int nFullPathname = pVfs->mxPathname+1;
  2197   2197         char *zFullPathname = sqlite3Malloc(MAX(nFullPathname,nFilename));
  2198   2198         MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
  2199   2199   
  2200   2200         p->sharable = 1;
  2201   2201         if( !zFullPathname ){
  2202   2202           sqlite3_free(p);
  2203         -        return SQLITE_NOMEM;
         2203  +        return SQLITE_NOMEM_BKPT;
  2204   2204         }
  2205   2205         if( isMemdb ){
  2206   2206           memcpy(zFullPathname, zFilename, nFilename);
  2207   2207         }else{
  2208   2208           rc = sqlite3OsFullPathname(pVfs, zFilename,
  2209   2209                                      nFullPathname, zFullPathname);
  2210   2210           if( rc ){
................................................................................
  2264   2264       assert( sizeof(u64)==8 );
  2265   2265       assert( sizeof(u32)==4 );
  2266   2266       assert( sizeof(u16)==2 );
  2267   2267       assert( sizeof(Pgno)==4 );
  2268   2268     
  2269   2269       pBt = sqlite3MallocZero( sizeof(*pBt) );
  2270   2270       if( pBt==0 ){
  2271         -      rc = SQLITE_NOMEM;
         2271  +      rc = SQLITE_NOMEM_BKPT;
  2272   2272         goto btree_open_out;
  2273   2273       }
  2274   2274       rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
  2275   2275                             EXTRA_SIZE, flags, vfsFlags, pageReinit);
  2276   2276       if( rc==SQLITE_OK ){
  2277   2277         sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
  2278   2278         rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
................................................................................
  2333   2333       if( p->sharable ){
  2334   2334         MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
  2335   2335         pBt->nRef = 1;
  2336   2336         MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
  2337   2337         if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
  2338   2338           pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
  2339   2339           if( pBt->mutex==0 ){
  2340         -          rc = SQLITE_NOMEM;
         2340  +          rc = SQLITE_NOMEM_BKPT;
  2341   2341             goto btree_open_out;
  2342   2342           }
  2343   2343         }
  2344   2344         sqlite3_mutex_enter(mutexShared);
  2345   2345         pBt->pNext = GLOBAL(BtShared*,sqlite3SharedCacheList);
  2346   2346         GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt;
  2347   2347         sqlite3_mutex_leave(mutexShared);
................................................................................
  4110   4110     assert( p->inTrans>TRANS_NONE );
  4111   4111     assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
  4112   4112     assert( pBt->pPage1 && pBt->pPage1->aData );
  4113   4113     assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );
  4114   4114   
  4115   4115     if( wrFlag ){
  4116   4116       allocateTempSpace(pBt);
  4117         -    if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM;
         4117  +    if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
  4118   4118     }
  4119   4119     if( iTable==1 && btreePagecount(pBt)==0 ){
  4120   4120       assert( wrFlag==0 );
  4121   4121       iTable = 0;
  4122   4122     }
  4123   4123   
  4124   4124     /* Now that no other errors can occur, finish filling in the BtCursor
................................................................................
  4508   4508       if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
  4509   4509         int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
  4510   4510         if( nOvfl>pCur->nOvflAlloc ){
  4511   4511           Pgno *aNew = (Pgno*)sqlite3Realloc(
  4512   4512               pCur->aOverflow, nOvfl*2*sizeof(Pgno)
  4513   4513           );
  4514   4514           if( aNew==0 ){
  4515         -          rc = SQLITE_NOMEM;
         4515  +          rc = SQLITE_NOMEM_BKPT;
  4516   4516           }else{
  4517   4517             pCur->nOvflAlloc = nOvfl*2;
  4518   4518             pCur->aOverflow = aNew;
  4519   4519           }
  4520   4520         }
  4521   4521         if( rc==SQLITE_OK ){
  4522   4522           memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
................................................................................
  5213   5213             testcase( nCell==2 );  /* Minimum legal index key size */
  5214   5214             if( nCell<2 ){
  5215   5215               rc = SQLITE_CORRUPT_BKPT;
  5216   5216               goto moveto_finish;
  5217   5217             }
  5218   5218             pCellKey = sqlite3Malloc( nCell+18 );
  5219   5219             if( pCellKey==0 ){
  5220         -            rc = SQLITE_NOMEM;
         5220  +            rc = SQLITE_NOMEM_BKPT;
  5221   5221               goto moveto_finish;
  5222   5222             }
  5223   5223             pCur->aiIdx[pCur->iPage] = (u16)idx;
  5224   5224             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
  5225   5225             if( rc ){
  5226   5226               sqlite3_free(pCellKey);
  5227   5227               goto moveto_finish;
................................................................................
  7032   7032     ** index iParentIdx. This scenario comes about when this function
  7033   7033     ** is called (indirectly) from sqlite3BtreeDelete().
  7034   7034     */
  7035   7035     assert( pParent->nOverflow==0 || pParent->nOverflow==1 );
  7036   7036     assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
  7037   7037   
  7038   7038     if( !aOvflSpace ){
  7039         -    return SQLITE_NOMEM;
         7039  +    return SQLITE_NOMEM_BKPT;
  7040   7040     }
  7041   7041   
  7042   7042     /* Find the sibling pages to balance. Also locate the cells in pParent 
  7043   7043     ** that divide the siblings. An attempt is made to find NN siblings on 
  7044   7044     ** either side of pPage. More siblings are taken from one side, however, 
  7045   7045     ** if there are fewer than NN siblings on the other side. If pParent
  7046   7046     ** has NB or fewer children then all children of pParent are taken.  
................................................................................
  7132   7132        + pBt->pageSize;                              /* aSpace1 */
  7133   7133   
  7134   7134     /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
  7135   7135     ** that is more than 6 times the database page size. */
  7136   7136     assert( szScratch<=6*(int)pBt->pageSize );
  7137   7137     b.apCell = sqlite3ScratchMalloc( szScratch ); 
  7138   7138     if( b.apCell==0 ){
  7139         -    rc = SQLITE_NOMEM;
         7139  +    rc = SQLITE_NOMEM_BKPT;
  7140   7140       goto balance_cleanup;
  7141   7141     }
  7142   7142     b.szCell = (u16*)&b.apCell[nMaxCells];
  7143   7143     aSpace1 = (u8*)&b.szCell[nMaxCells];
  7144   7144     assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
  7145   7145   
  7146   7146     /*

Changes to src/build.c.

   923    923         goto begin_table_error;
   924    924       }
   925    925     }
   926    926   
   927    927     pTable = sqlite3DbMallocZero(db, sizeof(Table));
   928    928     if( pTable==0 ){
   929    929       assert( db->mallocFailed );
   930         -    pParse->rc = SQLITE_NOMEM;
          930  +    pParse->rc = SQLITE_NOMEM_BKPT;
   931    931       pParse->nErr++;
   932    932       goto begin_table_error;
   933    933     }
   934    934     pTable->zName = zName;
   935    935     pTable->iPKey = -1;
   936    936     pTable->pSchema = db->aDb[iDb].pSchema;
   937    937     pTable->nRef = 1;
................................................................................
  1604   1604   static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
  1605   1605     char *zExtra;
  1606   1606     int nByte;
  1607   1607     if( pIdx->nColumn>=N ) return SQLITE_OK;
  1608   1608     assert( pIdx->isResized==0 );
  1609   1609     nByte = (sizeof(char*) + sizeof(i16) + 1)*N;
  1610   1610     zExtra = sqlite3DbMallocZero(db, nByte);
  1611         -  if( zExtra==0 ) return SQLITE_NOMEM;
         1611  +  if( zExtra==0 ) return SQLITE_NOMEM_BKPT;
  1612   1612     memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn);
  1613   1613     pIdx->azColl = (const char**)zExtra;
  1614   1614     zExtra += sizeof(char*)*N;
  1615   1615     memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn);
  1616   1616     pIdx->aiColumn = (i16*)zExtra;
  1617   1617     zExtra += sizeof(i16)*N;
  1618   1618     memcpy(zExtra, pIdx->aSortOrder, pIdx->nColumn);

Changes to src/complete.c.

   277    277   #endif
   278    278     pVal = sqlite3ValueNew(0);
   279    279     sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
   280    280     zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
   281    281     if( zSql8 ){
   282    282       rc = sqlite3_complete(zSql8);
   283    283     }else{
   284         -    rc = SQLITE_NOMEM;
          284  +    rc = SQLITE_NOMEM_BKPT;
   285    285     }
   286    286     sqlite3ValueFree(pVal);
   287    287     return rc & 0xff;
   288    288   }
   289    289   #endif /* SQLITE_OMIT_UTF16 */
   290    290   #endif /* SQLITE_OMIT_COMPLETE */

Changes to src/dbstat.c.

   158    158       }
   159    159     }else{
   160    160       iDb = 0;
   161    161     }
   162    162     rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
   163    163     if( rc==SQLITE_OK ){
   164    164       pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
   165         -    if( pTab==0 ) rc = SQLITE_NOMEM;
          165  +    if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
   166    166     }
   167    167   
   168    168     assert( rc==SQLITE_OK || pTab==0 );
   169    169     if( rc==SQLITE_OK ){
   170    170       memset(pTab, 0, sizeof(StatTable));
   171    171       pTab->db = db;
   172    172       pTab->iDb = iDb;
................................................................................
   239    239   */
   240    240   static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
   241    241     StatTable *pTab = (StatTable *)pVTab;
   242    242     StatCursor *pCsr;
   243    243   
   244    244     pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
   245    245     if( pCsr==0 ){
   246         -    return SQLITE_NOMEM;
          246  +    return SQLITE_NOMEM_BKPT;
   247    247     }else{
   248    248       memset(pCsr, 0, sizeof(StatCursor));
   249    249       pCsr->base.pVtab = pVTab;
   250    250       pCsr->iDb = pTab->iDb;
   251    251     }
   252    252   
   253    253     *ppCursor = (sqlite3_vtab_cursor *)pCsr;
................................................................................
   345    345       int i;                        /* Used to iterate through cells */
   346    346       int nUsable;                  /* Usable bytes per page */
   347    347   
   348    348       sqlite3BtreeEnter(pBt);
   349    349       nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt);
   350    350       sqlite3BtreeLeave(pBt);
   351    351       p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell));
   352         -    if( p->aCell==0 ) return SQLITE_NOMEM;
          352  +    if( p->aCell==0 ) return SQLITE_NOMEM_BKPT;
   353    353       memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell));
   354    354   
   355    355       for(i=0; i<p->nCell; i++){
   356    356         StatCell *pCell = &p->aCell[i];
   357    357   
   358    358         iOff = get2byte(&aData[nHdr+i*2]);
   359    359         if( !isLeaf ){
................................................................................
   378    378           assert( nLocal<=(nUsable-35) );
   379    379           if( nPayload>(u32)nLocal ){
   380    380             int j;
   381    381             int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
   382    382             pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
   383    383             pCell->nOvfl = nOvfl;
   384    384             pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
   385         -          if( pCell->aOvfl==0 ) return SQLITE_NOMEM;
          385  +          if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT;
   386    386             pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
   387    387             for(j=1; j<nOvfl; j++){
   388    388               int rc;
   389    389               u32 iPrev = pCell->aOvfl[j-1];
   390    390               DbPage *pPg = 0;
   391    391               rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0);
   392    392               if( rc!=SQLITE_OK ){
................................................................................
   457    457           return sqlite3_reset(pCsr->pStmt);
   458    458         }
   459    459         rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0);
   460    460         pCsr->aPage[0].iPgno = iRoot;
   461    461         pCsr->aPage[0].iCell = 0;
   462    462         pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
   463    463         pCsr->iPage = 0;
   464         -      if( z==0 ) rc = SQLITE_NOMEM;
          464  +      if( z==0 ) rc = SQLITE_NOMEM_BKPT;
   465    465       }else{
   466    466         pCsr->isEof = 1;
   467    467         return sqlite3_reset(pCsr->pStmt);
   468    468       }
   469    469     }else{
   470    470   
   471    471       /* Page p itself has already been visited. */
................................................................................
   492    492             pCsr->nPayload = nUsable - 4;
   493    493           }else{
   494    494             pCsr->nPayload = pCell->nLastOvfl;
   495    495             pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
   496    496           }
   497    497           pCell->iOvfl++;
   498    498           statSizeAndOffset(pCsr);
   499         -        return z==0 ? SQLITE_NOMEM : SQLITE_OK;
          499  +        return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
   500    500         }
   501    501         if( p->iRightChildPg ) break;
   502    502         p->iCell++;
   503    503       }
   504    504   
   505    505       if( !p->iRightChildPg || p->iCell>p->nCell ){
   506    506         statClearPage(p);
................................................................................
   516    516       }else{
   517    517         p[1].iPgno = p->aCell[p->iCell].iChildPg;
   518    518       }
   519    519       rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0);
   520    520       p[1].iCell = 0;
   521    521       p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
   522    522       p->iCell++;
   523         -    if( z==0 ) rc = SQLITE_NOMEM;
          523  +    if( z==0 ) rc = SQLITE_NOMEM_BKPT;
   524    524     }
   525    525   
   526    526   
   527    527     /* Populate the StatCursor fields with the values to be returned
   528    528     ** by the xColumn() and xRowid() methods.
   529    529     */
   530    530     if( rc==SQLITE_OK ){
................................................................................
   550    550             pCsr->zPagetype = "corrupted";
   551    551             break;
   552    552         }
   553    553         pCsr->nCell = p->nCell;
   554    554         pCsr->nUnused = p->nUnused;
   555    555         pCsr->nMxPayload = p->nMxPayload;
   556    556         pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath);
   557         -      if( z==0 ) rc = SQLITE_NOMEM;
          557  +      if( z==0 ) rc = SQLITE_NOMEM_BKPT;
   558    558         nPayload = 0;
   559    559         for(i=0; i<p->nCell; i++){
   560    560           nPayload += p->aCell[i].nLocal;
   561    561         }
   562    562         pCsr->nPayload = nPayload;
   563    563       }
   564    564     }
................................................................................
   584    584   
   585    585     if( idxNum==1 ){
   586    586       const char *zDbase = (const char*)sqlite3_value_text(argv[0]);
   587    587       pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
   588    588       if( pCsr->iDb<0 ){
   589    589         sqlite3_free(pCursor->pVtab->zErrMsg);
   590    590         pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
   591         -      return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
          591  +      return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM_BKPT;
   592    592       }
   593    593     }else{
   594    594       pCsr->iDb = pTab->iDb;
   595    595     }
   596    596     statResetCsr(pCsr);
   597    597     sqlite3_finalize(pCsr->pStmt);
   598    598     pCsr->pStmt = 0;
................................................................................
   600    600     zSql = sqlite3_mprintf(
   601    601         "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
   602    602         "  UNION ALL  "
   603    603         "SELECT name, rootpage, type"
   604    604         "  FROM \"%w\".%s WHERE rootpage!=0"
   605    605         "  ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
   606    606     if( zSql==0 ){
   607         -    return SQLITE_NOMEM;
          607  +    return SQLITE_NOMEM_BKPT;
   608    608     }else{
   609    609       rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
   610    610       sqlite3_free(zSql);
   611    611     }
   612    612   
   613    613     if( rc==SQLITE_OK ){
   614    614       rc = statNext(pCursor);

Changes to src/journal.c.

   208    208     int nBuf                   /* Bytes buffered before opening the file */
   209    209   ){
   210    210     JournalFile *p = (JournalFile *)pJfd;
   211    211     memset(p, 0, sqlite3JournalSize(pVfs));
   212    212     if( nBuf>0 ){
   213    213       p->zBuf = sqlite3MallocZero(nBuf);
   214    214       if( !p->zBuf ){
   215         -      return SQLITE_NOMEM;
          215  +      return SQLITE_NOMEM_BKPT;
   216    216       }
   217    217     }else{
   218    218       return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
   219    219     }
   220    220     p->pMethod = &JournalFileMethods;
   221    221     p->nBuf = nBuf;
   222    222     p->flags = flags;

Changes to src/legacy.c.

   127    127     rc = sqlite3ApiExit(db, rc);
   128    128     if( rc!=SQLITE_OK && pzErrMsg ){
   129    129       int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db));
   130    130       *pzErrMsg = sqlite3Malloc(nErrMsg);
   131    131       if( *pzErrMsg ){
   132    132         memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg);
   133    133       }else{
   134         -      rc = SQLITE_NOMEM;
          134  +      rc = SQLITE_NOMEM_BKPT;
   135    135         sqlite3Error(db, SQLITE_NOMEM);
   136    136       }
   137    137     }else if( pzErrMsg ){
   138    138       *pzErrMsg = 0;
   139    139     }
   140    140   
   141    141     assert( (rc&db->errMask)==rc );
   142    142     sqlite3_mutex_leave(db->mutex);
   143    143     return rc;
   144    144   }

Changes to src/loadext.c.

   474    474   
   475    475     zEntry = zProc ? zProc : "sqlite3_extension_init";
   476    476   
   477    477     handle = sqlite3OsDlOpen(pVfs, zFile);
   478    478   #if SQLITE_OS_UNIX || SQLITE_OS_WIN
   479    479     for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
   480    480       char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
   481         -    if( zAltFile==0 ) return SQLITE_NOMEM;
          481  +    if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
   482    482       handle = sqlite3OsDlOpen(pVfs, zAltFile);
   483    483       sqlite3_free(zAltFile);
   484    484     }
   485    485   #endif
   486    486     if( handle==0 ){
   487    487       if( pzErrMsg ){
   488    488         *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
................................................................................
   510    510     */
   511    511     if( xInit==0 && zProc==0 ){
   512    512       int iFile, iEntry, c;
   513    513       int ncFile = sqlite3Strlen30(zFile);
   514    514       zAltEntry = sqlite3_malloc64(ncFile+30);
   515    515       if( zAltEntry==0 ){
   516    516         sqlite3OsDlClose(pVfs, handle);
   517         -      return SQLITE_NOMEM;
          517  +      return SQLITE_NOMEM_BKPT;
   518    518       }
   519    519       memcpy(zAltEntry, "sqlite3_", 8);
   520    520       for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
   521    521       iFile++;
   522    522       if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
   523    523       for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
   524    524         if( sqlite3Isalpha(c) ){
................................................................................
   553    553       sqlite3OsDlClose(pVfs, handle);
   554    554       return SQLITE_ERROR;
   555    555     }
   556    556   
   557    557     /* Append the new shared library handle to the db->aExtension array. */
   558    558     aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
   559    559     if( aHandle==0 ){
   560         -    return SQLITE_NOMEM;
          560  +    return SQLITE_NOMEM_BKPT;
   561    561     }
   562    562     if( db->nExtension>0 ){
   563    563       memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
   564    564     }
   565    565     sqlite3DbFree(db, db->aExtension);
   566    566     db->aExtension = aHandle;
   567    567   
................................................................................
   675    675         if( wsdAutoext.aExt[i]==xInit ) break;
   676    676       }
   677    677       if( i==wsdAutoext.nExt ){
   678    678         u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
   679    679         void (**aNew)(void);
   680    680         aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
   681    681         if( aNew==0 ){
   682         -        rc = SQLITE_NOMEM;
          682  +        rc = SQLITE_NOMEM_BKPT;
   683    683         }else{
   684    684           wsdAutoext.aExt = aNew;
   685    685           wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
   686    686           wsdAutoext.nExt++;
   687    687         }
   688    688       }
   689    689       sqlite3_mutex_leave(mutex);

Changes to src/main.c.

   183    183     }
   184    184     if( rc==SQLITE_OK ){
   185    185       sqlite3GlobalConfig.isMallocInit = 1;
   186    186       if( !sqlite3GlobalConfig.pInitMutex ){
   187    187         sqlite3GlobalConfig.pInitMutex =
   188    188              sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
   189    189         if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
   190         -        rc = SQLITE_NOMEM;
          190  +        rc = SQLITE_NOMEM_BKPT;
   191    191         }
   192    192       }
   193    193     }
   194    194     if( rc==SQLITE_OK ){
   195    195       sqlite3GlobalConfig.nRefInitMutex++;
   196    196     }
   197    197     sqlite3_mutex_leave(pMaster);
................................................................................
  1641   1641         sqlite3ExpirePreparedStatements(db);
  1642   1642       }
  1643   1643     }
  1644   1644   
  1645   1645     p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
  1646   1646     assert(p || db->mallocFailed);
  1647   1647     if( !p ){
  1648         -    return SQLITE_NOMEM;
         1648  +    return SQLITE_NOMEM_BKPT;
  1649   1649     }
  1650   1650   
  1651   1651     /* If an older version of the function with a configured destructor is
  1652   1652     ** being replaced invoke the destructor function here. */
  1653   1653     functionDestroy(db, p);
  1654   1654   
  1655   1655     if( pDestructor ){
................................................................................
  2145   2145   /*
  2146   2146   ** Return UTF-8 encoded English language explanation of the most recent
  2147   2147   ** error.
  2148   2148   */
  2149   2149   const char *sqlite3_errmsg(sqlite3 *db){
  2150   2150     const char *z;
  2151   2151     if( !db ){
  2152         -    return sqlite3ErrStr(SQLITE_NOMEM);
         2152  +    return sqlite3ErrStr(SQLITE_NOMEM_BKPT);
  2153   2153     }
  2154   2154     if( !sqlite3SafetyCheckSickOrOk(db) ){
  2155   2155       return sqlite3ErrStr(SQLITE_MISUSE_BKPT);
  2156   2156     }
  2157   2157     sqlite3_mutex_enter(db->mutex);
  2158   2158     if( db->mallocFailed ){
  2159         -    z = sqlite3ErrStr(SQLITE_NOMEM);
         2159  +    z = sqlite3ErrStr(SQLITE_NOMEM_BKPT);
  2160   2160     }else{
  2161   2161       testcase( db->pErr==0 );
  2162   2162       z = (char*)sqlite3_value_text(db->pErr);
  2163   2163       assert( !db->mallocFailed );
  2164   2164       if( z==0 ){
  2165   2165         z = sqlite3ErrStr(db->errCode);
  2166   2166       }
................................................................................
  2220   2220   ** passed to this function, we assume a malloc() failed during sqlite3_open().
  2221   2221   */
  2222   2222   int sqlite3_errcode(sqlite3 *db){
  2223   2223     if( db && !sqlite3SafetyCheckSickOrOk(db) ){
  2224   2224       return SQLITE_MISUSE_BKPT;
  2225   2225     }
  2226   2226     if( !db || db->mallocFailed ){
  2227         -    return SQLITE_NOMEM;
         2227  +    return SQLITE_NOMEM_BKPT;
  2228   2228     }
  2229   2229     return db->errCode & db->errMask;
  2230   2230   }
  2231   2231   int sqlite3_extended_errcode(sqlite3 *db){
  2232   2232     if( db && !sqlite3SafetyCheckSickOrOk(db) ){
  2233   2233       return SQLITE_MISUSE_BKPT;
  2234   2234     }
  2235   2235     if( !db || db->mallocFailed ){
  2236         -    return SQLITE_NOMEM;
         2236  +    return SQLITE_NOMEM_BKPT;
  2237   2237     }
  2238   2238     return db->errCode;
  2239   2239   }
  2240   2240   
  2241   2241   /*
  2242   2242   ** Return a string that describes the kind of error specified in the
  2243   2243   ** argument.  For now, this simply calls the internal sqlite3ErrStr()
................................................................................
  2309   2309             p->xCmp = 0;
  2310   2310           }
  2311   2311         }
  2312   2312       }
  2313   2313     }
  2314   2314   
  2315   2315     pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
  2316         -  if( pColl==0 ) return SQLITE_NOMEM;
         2316  +  if( pColl==0 ) return SQLITE_NOMEM_BKPT;
  2317   2317     pColl->xCmp = xCompare;
  2318   2318     pColl->pUser = pCtx;
  2319   2319     pColl->xDel = xDel;
  2320   2320     pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
  2321   2321     sqlite3Error(db, SQLITE_OK);
  2322   2322     return SQLITE_OK;
  2323   2323   }
................................................................................
  2488   2488   
  2489   2489       /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen 
  2490   2490       ** method that there may be extra parameters following the file-name.  */
  2491   2491       flags |= SQLITE_OPEN_URI;
  2492   2492   
  2493   2493       for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
  2494   2494       zFile = sqlite3_malloc64(nByte);
  2495         -    if( !zFile ) return SQLITE_NOMEM;
         2495  +    if( !zFile ) return SQLITE_NOMEM_BKPT;
  2496   2496   
  2497   2497       iIn = 5;
  2498   2498   #ifdef SQLITE_ALLOW_URI_AUTHORITY
  2499   2499       if( strncmp(zUri+5, "///", 3)==0 ){
  2500   2500         iIn = 7;
  2501   2501         /* The following condition causes URIs with five leading / characters
  2502   2502         ** like file://///host/path to be converted into UNCs like //host/path.
................................................................................
  2654   2654         }
  2655   2655   
  2656   2656         zOpt = &zVal[nVal+1];
  2657   2657       }
  2658   2658   
  2659   2659     }else{
  2660   2660       zFile = sqlite3_malloc64(nUri+2);
  2661         -    if( !zFile ) return SQLITE_NOMEM;
         2661  +    if( !zFile ) return SQLITE_NOMEM_BKPT;
  2662   2662       memcpy(zFile, zUri, nUri);
  2663   2663       zFile[nUri] = '\0';
  2664   2664       zFile[nUri+1] = '\0';
  2665   2665       flags &= ~SQLITE_OPEN_URI;
  2666   2666     }
  2667   2667   
  2668   2668     *ppVfs = sqlite3_vfs_find(zVfs);
................................................................................
  2853   2853     }
  2854   2854   
  2855   2855     /* Open the backend database driver */
  2856   2856     rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
  2857   2857                           flags | SQLITE_OPEN_MAIN_DB);
  2858   2858     if( rc!=SQLITE_OK ){
  2859   2859       if( rc==SQLITE_IOERR_NOMEM ){
  2860         -      rc = SQLITE_NOMEM;
         2860  +      rc = SQLITE_NOMEM_BKPT;
  2861   2861       }
  2862   2862       sqlite3Error(db, rc);
  2863   2863       goto opendb_out;
  2864   2864     }
  2865   2865     sqlite3BtreeEnter(db->aDb[0].pBt);
  2866   2866     db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
  2867   2867     if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
................................................................................
  3056   3056       rc = openDatabase(zFilename8, ppDb,
  3057   3057                         SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
  3058   3058       assert( *ppDb || rc==SQLITE_NOMEM );
  3059   3059       if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
  3060   3060         SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
  3061   3061       }
  3062   3062     }else{
  3063         -    rc = SQLITE_NOMEM;
         3063  +    rc = SQLITE_NOMEM_BKPT;
  3064   3064     }
  3065   3065     sqlite3ValueFree(pVal);
  3066   3066   
  3067   3067     return rc & 0xff;
  3068   3068   }
  3069   3069   #endif /* SQLITE_OMIT_UTF16 */
  3070   3070   
................................................................................
  3231   3231   int sqlite3CantopenError(int lineno){
  3232   3232     testcase( sqlite3GlobalConfig.xLog!=0 );
  3233   3233     sqlite3_log(SQLITE_CANTOPEN, 
  3234   3234                 "cannot open file at line %d of [%.10s]",
  3235   3235                 lineno, 20+sqlite3_sourceid());
  3236   3236     return SQLITE_CANTOPEN;
  3237   3237   }
  3238         -
         3238  +int sqlite3NomemError(int lineno){
         3239  +  testcase( sqlite3GlobalConfig.xLog!=0 );
         3240  +  sqlite3_log(SQLITE_NOMEM, 
         3241  +              "out of memory at line %d of [%.10s]",
         3242  +              lineno, 20+sqlite3_sourceid());
         3243  +  return SQLITE_NOMEM;
         3244  +}
         3245  +int sqlite3IoerrnomemError(int lineno){
         3246  +  testcase( sqlite3GlobalConfig.xLog!=0 );
         3247  +  sqlite3_log(SQLITE_IOERR_NOMEM, 
         3248  +              "out of memory for I/O at line %d of [%.10s]",
         3249  +              lineno, 20+sqlite3_sourceid());
         3250  +  return SQLITE_IOERR_NOMEM;
         3251  +}
  3239   3252   
  3240   3253   #ifndef SQLITE_OMIT_DEPRECATED
  3241   3254   /*
  3242   3255   ** This is a convenience routine that makes sure that all thread-specific
  3243   3256   ** data for this thread has been deallocated.
  3244   3257   **
  3245   3258   ** SQLite no longer uses thread-specific data so this routine is now a

Changes to src/malloc.c.

   791    791   
   792    792   /*
   793    793   ** Take actions at the end of an API call to indicate an OOM error
   794    794   */
   795    795   static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
   796    796     sqlite3OomClear(db);
   797    797     sqlite3Error(db, SQLITE_NOMEM);
   798         -  return SQLITE_NOMEM;
          798  +  return SQLITE_NOMEM_BKPT;
   799    799   }
   800    800   
   801    801   /*
   802    802   ** This function must be called before exiting any API function (i.e. 
   803    803   ** returning control to the user) that has called sqlite3_malloc or
   804    804   ** sqlite3_realloc.
   805    805   **

Changes to src/memjournal.c.

   129    129       int iChunkOffset = (int)(p->endpoint.iOffset%JOURNAL_CHUNKSIZE);
   130    130       int iSpace = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset);
   131    131   
   132    132       if( iChunkOffset==0 ){
   133    133         /* New chunk is required to extend the file. */
   134    134         FileChunk *pNew = sqlite3_malloc(sizeof(FileChunk));
   135    135         if( !pNew ){
   136         -        return SQLITE_IOERR_NOMEM;
          136  +        return SQLITE_IOERR_NOMEM_BKPT;
   137    137         }
   138    138         pNew->pNext = 0;
   139    139         if( pChunk ){
   140    140           assert( p->pFirst );
   141    141           pChunk->pNext = pNew;
   142    142         }else{
   143    143           assert( !p->pFirst );

Changes to src/os.c.

    64     64   **
    65     65   */
    66     66   #if defined(SQLITE_TEST)
    67     67   int sqlite3_memdebug_vfs_oom_test = 1;
    68     68     #define DO_OS_MALLOC_TEST(x)                                       \
    69     69     if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) {  \
    70     70       void *pTstAlloc = sqlite3Malloc(10);                             \
    71         -    if (!pTstAlloc) return SQLITE_IOERR_NOMEM;                       \
           71  +    if (!pTstAlloc) return SQLITE_IOERR_NOMEM_BKPT;                  \
    72     72       sqlite3_free(pTstAlloc);                                         \
    73     73     }
    74     74   #else
    75     75     #define DO_OS_MALLOC_TEST(x)
    76     76   #endif
    77     77   
    78     78   /*
................................................................................
   283    283   int sqlite3OsOpenMalloc(
   284    284     sqlite3_vfs *pVfs,
   285    285     const char *zFile,
   286    286     sqlite3_file **ppFile,
   287    287     int flags,
   288    288     int *pOutFlags
   289    289   ){
   290         -  int rc = SQLITE_NOMEM;
          290  +  int rc;
   291    291     sqlite3_file *pFile;
   292    292     pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
   293    293     if( pFile ){
   294    294       rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
   295    295       if( rc!=SQLITE_OK ){
   296    296         sqlite3_free(pFile);
   297    297       }else{
   298    298         *ppFile = pFile;
   299    299       }
          300  +  }else{
          301  +    rc = SQLITE_NOMEM_BKPT;
   300    302     }
   301    303     return rc;
   302    304   }
   303    305   int sqlite3OsCloseFree(sqlite3_file *pFile){
   304    306     int rc = SQLITE_OK;
   305    307     assert( pFile );
   306    308     rc = sqlite3OsClose(pFile);
................................................................................
   312    314   ** This function is a wrapper around the OS specific implementation of
   313    315   ** sqlite3_os_init(). The purpose of the wrapper is to provide the
   314    316   ** ability to simulate a malloc failure, so that the handling of an
   315    317   ** error in sqlite3_os_init() by the upper layers can be tested.
   316    318   */
   317    319   int sqlite3OsInit(void){
   318    320     void *p = sqlite3_malloc(10);
   319         -  if( p==0 ) return SQLITE_NOMEM;
          321  +  if( p==0 ) return SQLITE_NOMEM_BKPT;
   320    322     sqlite3_free(p);
   321    323     return sqlite3_os_init();
   322    324   }
   323    325   
   324    326   /*
   325    327   ** The list of all registered VFS implementations.
   326    328   */

Changes to src/os_unix.c.

  1298   1298     pInode = inodeList;
  1299   1299     while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
  1300   1300       pInode = pInode->pNext;
  1301   1301     }
  1302   1302     if( pInode==0 ){
  1303   1303       pInode = sqlite3_malloc64( sizeof(*pInode) );
  1304   1304       if( pInode==0 ){
  1305         -      return SQLITE_NOMEM;
         1305  +      return SQLITE_NOMEM_BKPT;
  1306   1306       }
  1307   1307       memset(pInode, 0, sizeof(*pInode));
  1308   1308       memcpy(&pInode->fileId, &fileId, sizeof(fileId));
  1309   1309       pInode->nRef = 1;
  1310   1310       pInode->pNext = inodeList;
  1311   1311       pInode->pPrev = 0;
  1312   1312       if( inodeList ) inodeList->pPrev = pInode;
................................................................................
  4218   4218     int rc;                         /* Result code */
  4219   4219     unixInodeInfo *pInode;          /* The inode of fd */
  4220   4220     char *zShmFilename;             /* Name of the file used for SHM */
  4221   4221     int nShmFilename;               /* Size of the SHM filename in bytes */
  4222   4222   
  4223   4223     /* Allocate space for the new unixShm object. */
  4224   4224     p = sqlite3_malloc64( sizeof(*p) );
  4225         -  if( p==0 ) return SQLITE_NOMEM;
         4225  +  if( p==0 ) return SQLITE_NOMEM_BKPT;
  4226   4226     memset(p, 0, sizeof(*p));
  4227   4227     assert( pDbFd->pShm==0 );
  4228   4228   
  4229   4229     /* Check to see if a unixShmNode object already exists. Reuse an existing
  4230   4230     ** one if present. Create a new one if necessary.
  4231   4231     */
  4232   4232     unixEnterMutex();
................................................................................
  4250   4250   #ifdef SQLITE_SHM_DIRECTORY
  4251   4251       nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
  4252   4252   #else
  4253   4253       nShmFilename = 6 + (int)strlen(zBasePath);
  4254   4254   #endif
  4255   4255       pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
  4256   4256       if( pShmNode==0 ){
  4257         -      rc = SQLITE_NOMEM;
         4257  +      rc = SQLITE_NOMEM_BKPT;
  4258   4258         goto shm_open_err;
  4259   4259       }
  4260   4260       memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
  4261   4261       zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
  4262   4262   #ifdef SQLITE_SHM_DIRECTORY
  4263   4263       sqlite3_snprintf(nShmFilename, zShmFilename, 
  4264   4264                        SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
................................................................................
  4268   4268       sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
  4269   4269   #endif
  4270   4270       pShmNode->h = -1;
  4271   4271       pDbFd->pInode->pShmNode = pShmNode;
  4272   4272       pShmNode->pInode = pDbFd->pInode;
  4273   4273       pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  4274   4274       if( pShmNode->mutex==0 ){
  4275         -      rc = SQLITE_NOMEM;
         4275  +      rc = SQLITE_NOMEM_BKPT;
  4276   4276         goto shm_open_err;
  4277   4277       }
  4278   4278   
  4279   4279       if( pInode->bProcessLock==0 ){
  4280   4280         int openFlags = O_RDWR | O_CREAT;
  4281   4281         if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
  4282   4282           openFlags = O_RDONLY;
................................................................................
  4441   4441       }
  4442   4442   
  4443   4443       /* Map the requested memory region into this processes address space. */
  4444   4444       apNew = (char **)sqlite3_realloc(
  4445   4445           pShmNode->apRegion, nReqRegion*sizeof(char *)
  4446   4446       );
  4447   4447       if( !apNew ){
  4448         -      rc = SQLITE_IOERR_NOMEM;
         4448  +      rc = SQLITE_IOERR_NOMEM_BKPT;
  4449   4449         goto shmpage_out;
  4450   4450       }
  4451   4451       pShmNode->apRegion = apNew;
  4452   4452       while( pShmNode->nRegion<nReqRegion ){
  4453   4453         int nMap = szRegion*nShmPerMap;
  4454   4454         int i;
  4455   4455         void *pMem;
................................................................................
  4461   4461           if( pMem==MAP_FAILED ){
  4462   4462             rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
  4463   4463             goto shmpage_out;
  4464   4464           }
  4465   4465         }else{
  4466   4466           pMem = sqlite3_malloc64(szRegion);
  4467   4467           if( pMem==0 ){
  4468         -          rc = SQLITE_NOMEM;
         4468  +          rc = SQLITE_NOMEM_BKPT;
  4469   4469             goto shmpage_out;
  4470   4470           }
  4471   4471           memset(pMem, 0, szRegion);
  4472   4472         }
  4473   4473   
  4474   4474         for(i=0; i<nShmPerMap; i++){
  4475   4475           pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i];
................................................................................
  5239   5239       pNew->ctrlFlags |= UNIXFILE_EXCL;
  5240   5240     }
  5241   5241   
  5242   5242   #if OS_VXWORKS
  5243   5243     pNew->pId = vxworksFindFileId(zFilename);
  5244   5244     if( pNew->pId==0 ){
  5245   5245       ctrlFlags |= UNIXFILE_NOLOCK;
  5246         -    rc = SQLITE_NOMEM;
         5246  +    rc = SQLITE_NOMEM_BKPT;
  5247   5247     }
  5248   5248   #endif
  5249   5249   
  5250   5250     if( ctrlFlags & UNIXFILE_NOLOCK ){
  5251   5251       pLockingStyle = &nolockIoMethods;
  5252   5252     }else{
  5253   5253       pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
................................................................................
  5295   5295     else if( pLockingStyle == &afpIoMethods ){
  5296   5296       /* AFP locking uses the file path so it needs to be included in
  5297   5297       ** the afpLockingContext.
  5298   5298       */
  5299   5299       afpLockingContext *pCtx;
  5300   5300       pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
  5301   5301       if( pCtx==0 ){
  5302         -      rc = SQLITE_NOMEM;
         5302  +      rc = SQLITE_NOMEM_BKPT;
  5303   5303       }else{
  5304   5304         /* NB: zFilename exists and remains valid until the file is closed
  5305   5305         ** according to requirement F11141.  So we do not need to make a
  5306   5306         ** copy of the filename. */
  5307   5307         pCtx->dbPath = zFilename;
  5308   5308         pCtx->reserved = 0;
  5309   5309         srandomdev();
................................................................................
  5325   5325       */
  5326   5326       char *zLockFile;
  5327   5327       int nFilename;
  5328   5328       assert( zFilename!=0 );
  5329   5329       nFilename = (int)strlen(zFilename) + 6;
  5330   5330       zLockFile = (char *)sqlite3_malloc64(nFilename);
  5331   5331       if( zLockFile==0 ){
  5332         -      rc = SQLITE_NOMEM;
         5332  +      rc = SQLITE_NOMEM_BKPT;
  5333   5333       }else{
  5334   5334         sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
  5335   5335       }
  5336   5336       pNew->lockingContext = zLockFile;
  5337   5337     }
  5338   5338   
  5339   5339   #if OS_VXWORKS
................................................................................
  5348   5348         int n;
  5349   5349         sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem",
  5350   5350                          pNew->pId->zCanonicalName);
  5351   5351         for( n=1; zSemName[n]; n++ )
  5352   5352           if( zSemName[n]=='/' ) zSemName[n] = '_';
  5353   5353         pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1);
  5354   5354         if( pNew->pInode->pSem == SEM_FAILED ){
  5355         -        rc = SQLITE_NOMEM;
         5355  +        rc = SQLITE_NOMEM_BKPT;
  5356   5356           pNew->pInode->aSemName[0] = '\0';
  5357   5357         }
  5358   5358       }
  5359   5359       unixLeaveMutex();
  5360   5360     }
  5361   5361   #endif
  5362   5362     
................................................................................
  5689   5689       UnixUnusedFd *pUnused;
  5690   5690       pUnused = findReusableFd(zName, flags);
  5691   5691       if( pUnused ){
  5692   5692         fd = pUnused->fd;
  5693   5693       }else{
  5694   5694         pUnused = sqlite3_malloc64(sizeof(*pUnused));
  5695   5695         if( !pUnused ){
  5696         -        return SQLITE_NOMEM;
         5696  +        return SQLITE_NOMEM_BKPT;
  5697   5697         }
  5698   5698       }
  5699   5699       p->pUnused = pUnused;
  5700   5700   
  5701   5701       /* Database filenames are double-zero terminated if they are not
  5702   5702       ** URIs with parameters.  Hence, they can always be passed into
  5703   5703       ** sqlite3_uri_parameter(). */
................................................................................
  5775   5775     if( isDelete ){
  5776   5776   #if OS_VXWORKS
  5777   5777       zPath = zName;
  5778   5778   #elif defined(SQLITE_UNLINK_AFTER_CLOSE)
  5779   5779       zPath = sqlite3_mprintf("%s", zName);
  5780   5780       if( zPath==0 ){
  5781   5781         robust_close(p, fd, __LINE__);
  5782         -      return SQLITE_NOMEM;
         5782  +      return SQLITE_NOMEM_BKPT;
  5783   5783       }
  5784   5784   #else
  5785   5785       osUnlink(zName);
  5786   5786   #endif
  5787   5787     }
  5788   5788   #if SQLITE_ENABLE_LOCKING_STYLE
  5789   5789     else{
................................................................................
  6007   6007       }else{
  6008   6008         bLink = S_ISLNK(buf.st_mode);
  6009   6009       }
  6010   6010   
  6011   6011       if( bLink ){
  6012   6012         if( zDel==0 ){
  6013   6013           zDel = sqlite3_malloc(nOut);
  6014         -        if( zDel==0 ) rc = SQLITE_NOMEM;
         6014  +        if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
  6015   6015         }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
  6016   6016           rc = SQLITE_CANTOPEN_BKPT;
  6017   6017         }
  6018   6018   
  6019   6019         if( rc==SQLITE_OK ){
  6020   6020           nByte = osReadlink(zIn, zDel, nOut-1);
  6021   6021           if( nByte<0 ){
................................................................................
  6551   6551     */
  6552   6552     pUnused = findReusableFd(path, openFlags);
  6553   6553     if( pUnused ){
  6554   6554       fd = pUnused->fd;
  6555   6555     }else{
  6556   6556       pUnused = sqlite3_malloc64(sizeof(*pUnused));
  6557   6557       if( !pUnused ){
  6558         -      return SQLITE_NOMEM;
         6558  +      return SQLITE_NOMEM_BKPT;
  6559   6559       }
  6560   6560     }
  6561   6561     if( fd<0 ){
  6562   6562       fd = robust_open(path, openFlags, 0);
  6563   6563       terrno = errno;
  6564   6564       if( fd<0 && errno==ENOENT && islockfile ){
  6565   6565         if( proxyCreateLockPath(path) == SQLITE_OK ){
................................................................................
  6584   6584         default:
  6585   6585           return SQLITE_CANTOPEN_BKPT;
  6586   6586       }
  6587   6587     }
  6588   6588     
  6589   6589     pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
  6590   6590     if( pNew==NULL ){
  6591         -    rc = SQLITE_NOMEM;
         6591  +    rc = SQLITE_NOMEM_BKPT;
  6592   6592       goto end_create_proxy;
  6593   6593     }
  6594   6594     memset(pNew, 0, sizeof(unixFile));
  6595   6595     pNew->openFlags = openFlags;
  6596   6596     memset(&dummyVfs, 0, sizeof(dummyVfs));
  6597   6597     dummyVfs.pAppData = (void*)&autolockIoFinder;
  6598   6598     dummyVfs.zName = "dummy";
................................................................................
  6997   6997         if( rc==SQLITE_OK ){
  6998   6998           /* Need to make a copy of path if we extracted the value
  6999   6999            ** from the conch file or the path was allocated on the stack
  7000   7000            */
  7001   7001           if( tempLockPath ){
  7002   7002             pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath);
  7003   7003             if( !pCtx->lockProxyPath ){
  7004         -            rc = SQLITE_NOMEM;
         7004  +            rc = SQLITE_NOMEM_BKPT;
  7005   7005             }
  7006   7006           }
  7007   7007         }
  7008   7008         if( rc==SQLITE_OK ){
  7009   7009           pCtx->conchHeld = 1;
  7010   7010           
  7011   7011           if( pCtx->lockProxy->pMethod == &afpIoMethods ){
................................................................................
  7062   7062     int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
  7063   7063     char *conchPath;              /* buffer in which to construct conch name */
  7064   7064   
  7065   7065     /* Allocate space for the conch filename and initialize the name to
  7066   7066     ** the name of the original database file. */  
  7067   7067     *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
  7068   7068     if( conchPath==0 ){
  7069         -    return SQLITE_NOMEM;
         7069  +    return SQLITE_NOMEM_BKPT;
  7070   7070     }
  7071   7071     memcpy(conchPath, dbPath, len+1);
  7072   7072     
  7073   7073     /* now insert a "." before the last / character */
  7074   7074     for( i=(len-1); i>=0; i-- ){
  7075   7075       if( conchPath[i]=='/' ){
  7076   7076         i++;
................................................................................
  7178   7178     }
  7179   7179     
  7180   7180     OSTRACE(("TRANSPROXY  %d for %s pid=%d\n", pFile->h,
  7181   7181              (lockPath ? lockPath : ":auto:"), osGetpid(0)));
  7182   7182   
  7183   7183     pCtx = sqlite3_malloc64( sizeof(*pCtx) );
  7184   7184     if( pCtx==0 ){
  7185         -    return SQLITE_NOMEM;
         7185  +    return SQLITE_NOMEM_BKPT;
  7186   7186     }
  7187   7187     memset(pCtx, 0, sizeof(*pCtx));
  7188   7188   
  7189   7189     rc = proxyCreateConchPathname(dbPath, &pCtx->conchFilePath);
  7190   7190     if( rc==SQLITE_OK ){
  7191   7191       rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0);
  7192   7192       if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
................................................................................
  7214   7214     if( rc==SQLITE_OK && lockPath ){
  7215   7215       pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath);
  7216   7216     }
  7217   7217   
  7218   7218     if( rc==SQLITE_OK ){
  7219   7219       pCtx->dbPath = sqlite3DbStrDup(0, dbPath);
  7220   7220       if( pCtx->dbPath==NULL ){
  7221         -      rc = SQLITE_NOMEM;
         7221  +      rc = SQLITE_NOMEM_BKPT;
  7222   7222       }
  7223   7223     }
  7224   7224     if( rc==SQLITE_OK ){
  7225   7225       /* all memory is allocated, proxys are created and assigned, 
  7226   7226       ** switch the locking context and pMethod then return.
  7227   7227       */
  7228   7228       pCtx->oldLockingContext = pFile->lockingContext;

Changes to src/os_win.c.

  1218   1218   #endif
  1219   1219   #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
  1220   1220     if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
  1221   1221       DWORD lastErrno = osGetLastError();
  1222   1222       if( lastErrno==NO_ERROR ){
  1223   1223         sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
  1224   1224                     (void*)hHeap);
  1225         -      rc = SQLITE_NOMEM;
         1225  +      rc = SQLITE_NOMEM_BKPT;
  1226   1226       }else{
  1227   1227         sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
  1228   1228                     osGetLastError(), (void*)hHeap);
  1229   1229         rc = SQLITE_ERROR;
  1230   1230       }
  1231   1231     }
  1232   1232   #else
................................................................................
  1538   1538       pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
  1539   1539                                         dwInitialSize, dwMaximumSize);
  1540   1540       if( !pWinMemData->hHeap ){
  1541   1541         sqlite3_log(SQLITE_NOMEM,
  1542   1542             "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu",
  1543   1543             osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize,
  1544   1544             dwMaximumSize);
  1545         -      return SQLITE_NOMEM;
         1545  +      return SQLITE_NOMEM_BKPT;
  1546   1546       }
  1547   1547       pWinMemData->bOwned = TRUE;
  1548   1548       assert( pWinMemData->bOwned );
  1549   1549     }
  1550   1550   #else
  1551   1551     pWinMemData->hHeap = osGetProcessHeap();
  1552   1552     if( !pWinMemData->hHeap ){
  1553   1553       sqlite3_log(SQLITE_NOMEM,
  1554   1554           "failed to GetProcessHeap (%lu)", osGetLastError());
  1555         -    return SQLITE_NOMEM;
         1555  +    return SQLITE_NOMEM_BKPT;
  1556   1556     }
  1557   1557     pWinMemData->bOwned = FALSE;
  1558   1558     assert( !pWinMemData->bOwned );
  1559   1559   #endif
  1560   1560     assert( pWinMemData->hHeap!=0 );
  1561   1561     assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
  1562   1562   #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
................................................................................
  1785   1785     );
  1786   1786     assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) );
  1787   1787     if( ppDirectory ){
  1788   1788       char *zValueUtf8 = 0;
  1789   1789       if( zValue && zValue[0] ){
  1790   1790         zValueUtf8 = winUnicodeToUtf8(zValue);
  1791   1791         if ( zValueUtf8==0 ){
  1792         -        return SQLITE_NOMEM;
         1792  +        return SQLITE_NOMEM_BKPT;
  1793   1793         }
  1794   1794       }
  1795   1795       sqlite3_free(*ppDirectory);
  1796   1796       *ppDirectory = zValueUtf8;
  1797   1797       return SQLITE_OK;
  1798   1798     }
  1799   1799     return SQLITE_ERROR;
................................................................................
  2062   2062     DWORD lastErrno;
  2063   2063     BOOL bLogged = FALSE;
  2064   2064     BOOL bInit = TRUE;
  2065   2065   
  2066   2066     zName = winUtf8ToUnicode(zFilename);
  2067   2067     if( zName==0 ){
  2068   2068       /* out of memory */
  2069         -    return SQLITE_IOERR_NOMEM;
         2069  +    return SQLITE_IOERR_NOMEM_BKPT;
  2070   2070     }
  2071   2071   
  2072   2072     /* Initialize the local lockdata */
  2073   2073     memset(&pFile->local, 0, sizeof(pFile->local));
  2074   2074   
  2075   2075     /* Replace the backslashes from the filename and lowercase it
  2076   2076     ** to derive a mutex name. */
................................................................................
  3611   3611   
  3612   3612     assert( pDbFd->pShm==0 );    /* Not previously opened */
  3613   3613   
  3614   3614     /* Allocate space for the new sqlite3_shm object.  Also speculatively
  3615   3615     ** allocate space for a new winShmNode and filename.
  3616   3616     */
  3617   3617     p = sqlite3MallocZero( sizeof(*p) );
  3618         -  if( p==0 ) return SQLITE_IOERR_NOMEM;
         3618  +  if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
  3619   3619     nName = sqlite3Strlen30(pDbFd->zPath);
  3620   3620     pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
  3621   3621     if( pNew==0 ){
  3622   3622       sqlite3_free(p);
  3623         -    return SQLITE_IOERR_NOMEM;
         3623  +    return SQLITE_IOERR_NOMEM_BKPT;
  3624   3624     }
  3625   3625     pNew->zFilename = (char*)&pNew[1];
  3626   3626     sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
  3627   3627     sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
  3628   3628   
  3629   3629     /* Look to see if there is an existing winShmNode that can be used.
  3630   3630     ** If no matching winShmNode currently exists, create a new one.
................................................................................
  3643   3643       pNew = 0;
  3644   3644       ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
  3645   3645       pShmNode->pNext = winShmNodeList;
  3646   3646       winShmNodeList = pShmNode;
  3647   3647   
  3648   3648       pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  3649   3649       if( pShmNode->mutex==0 ){
  3650         -      rc = SQLITE_IOERR_NOMEM;
         3650  +      rc = SQLITE_IOERR_NOMEM_BKPT;
  3651   3651         goto shm_open_err;
  3652   3652       }
  3653   3653   
  3654   3654       rc = winOpen(pDbFd->pVfs,
  3655   3655                    pShmNode->zFilename,             /* Name of the file (UTF-8) */
  3656   3656                    (sqlite3_file*)&pShmNode->hFile,  /* File handle here */
  3657   3657                    SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
................................................................................
  3948   3948       }
  3949   3949   
  3950   3950       /* Map the requested memory region into this processes address space. */
  3951   3951       apNew = (struct ShmRegion *)sqlite3_realloc64(
  3952   3952           pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
  3953   3953       );
  3954   3954       if( !apNew ){
  3955         -      rc = SQLITE_IOERR_NOMEM;
         3955  +      rc = SQLITE_IOERR_NOMEM_BKPT;
  3956   3956         goto shmpage_out;
  3957   3957       }
  3958   3958       pShmNode->aRegion = apNew;
  3959   3959   
  3960   3960       while( pShmNode->nRegion<=iRegion ){
  3961   3961         HANDLE hMap = NULL;         /* file-mapping handle */
  3962   3962         void *pMap = 0;             /* Mapped memory region */
................................................................................
  4378   4378     /* Allocate a temporary buffer to store the fully qualified file
  4379   4379     ** name for the temporary file.  If this fails, we cannot continue.
  4380   4380     */
  4381   4381     nMax = pVfs->mxPathname; nBuf = nMax + 2;
  4382   4382     zBuf = sqlite3MallocZero( nBuf );
  4383   4383     if( !zBuf ){
  4384   4384       OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4385         -    return SQLITE_IOERR_NOMEM;
         4385  +    return SQLITE_IOERR_NOMEM_BKPT;
  4386   4386     }
  4387   4387   
  4388   4388     /* Figure out the effective temporary directory.  First, check if one
  4389   4389     ** has been explicitly set by the application; otherwise, use the one
  4390   4390     ** configured by the operating system.
  4391   4391     */
  4392   4392     nDir = nMax - (nPre + 15);
................................................................................
  4436   4436         ** prior to using it.
  4437   4437         */
  4438   4438         if( winIsDriveLetterAndColon(zDir) ){
  4439   4439           zConverted = winConvertFromUtf8Filename(zDir);
  4440   4440           if( !zConverted ){
  4441   4441             sqlite3_free(zBuf);
  4442   4442             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4443         -          return SQLITE_IOERR_NOMEM;
         4443  +          return SQLITE_IOERR_NOMEM_BKPT;
  4444   4444           }
  4445   4445           if( winIsDir(zConverted) ){
  4446   4446             sqlite3_snprintf(nMax, zBuf, "%s", zDir);
  4447   4447             sqlite3_free(zConverted);
  4448   4448             break;
  4449   4449           }
  4450   4450           sqlite3_free(zConverted);
  4451   4451         }else{
  4452   4452           zConverted = sqlite3MallocZero( nMax+1 );
  4453   4453           if( !zConverted ){
  4454   4454             sqlite3_free(zBuf);
  4455   4455             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4456         -          return SQLITE_IOERR_NOMEM;
         4456  +          return SQLITE_IOERR_NOMEM_BKPT;
  4457   4457           }
  4458   4458           if( cygwin_conv_path(
  4459   4459                   osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
  4460   4460                   zConverted, nMax+1)<0 ){
  4461   4461             sqlite3_free(zConverted);
  4462   4462             sqlite3_free(zBuf);
  4463   4463             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
................................................................................
  4470   4470             ** its name into UTF-8 (i.e. if it is UTF-16 right now).
  4471   4471             */
  4472   4472             char *zUtf8 = winConvertToUtf8Filename(zConverted);
  4473   4473             if( !zUtf8 ){
  4474   4474               sqlite3_free(zConverted);
  4475   4475               sqlite3_free(zBuf);
  4476   4476               OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4477         -            return SQLITE_IOERR_NOMEM;
         4477  +            return SQLITE_IOERR_NOMEM_BKPT;
  4478   4478             }
  4479   4479             sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
  4480   4480             sqlite3_free(zUtf8);
  4481   4481             sqlite3_free(zConverted);
  4482   4482             break;
  4483   4483           }
  4484   4484           sqlite3_free(zConverted);
................................................................................
  4488   4488   #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
  4489   4489     else if( osIsNT() ){
  4490   4490       char *zMulti;
  4491   4491       LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
  4492   4492       if( !zWidePath ){
  4493   4493         sqlite3_free(zBuf);
  4494   4494         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4495         -      return SQLITE_IOERR_NOMEM;
         4495  +      return SQLITE_IOERR_NOMEM_BKPT;
  4496   4496       }
  4497   4497       if( osGetTempPathW(nMax, zWidePath)==0 ){
  4498   4498         sqlite3_free(zWidePath);
  4499   4499         sqlite3_free(zBuf);
  4500   4500         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
  4501   4501         return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
  4502   4502                            "winGetTempname2", 0);
................................................................................
  4506   4506         sqlite3_snprintf(nMax, zBuf, "%s", zMulti);
  4507   4507         sqlite3_free(zMulti);
  4508   4508         sqlite3_free(zWidePath);
  4509   4509       }else{
  4510   4510         sqlite3_free(zWidePath);
  4511   4511         sqlite3_free(zBuf);
  4512   4512         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4513         -      return SQLITE_IOERR_NOMEM;
         4513  +      return SQLITE_IOERR_NOMEM_BKPT;
  4514   4514       }
  4515   4515     }
  4516   4516   #ifdef SQLITE_WIN32_HAS_ANSI
  4517   4517     else{
  4518   4518       char *zUtf8;
  4519   4519       char *zMbcsPath = sqlite3MallocZero( nMax );
  4520   4520       if( !zMbcsPath ){
  4521   4521         sqlite3_free(zBuf);
  4522   4522         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4523         -      return SQLITE_IOERR_NOMEM;
         4523  +      return SQLITE_IOERR_NOMEM_BKPT;
  4524   4524       }
  4525   4525       if( osGetTempPathA(nMax, zMbcsPath)==0 ){
  4526   4526         sqlite3_free(zBuf);
  4527   4527         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
  4528   4528         return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
  4529   4529                            "winGetTempname3", 0);
  4530   4530       }
................................................................................
  4531   4531       zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
  4532   4532       if( zUtf8 ){
  4533   4533         sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
  4534   4534         sqlite3_free(zUtf8);
  4535   4535       }else{
  4536   4536         sqlite3_free(zBuf);
  4537   4537         OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4538         -      return SQLITE_IOERR_NOMEM;
         4538  +      return SQLITE_IOERR_NOMEM_BKPT;
  4539   4539       }
  4540   4540     }
  4541   4541   #endif /* SQLITE_WIN32_HAS_ANSI */
  4542   4542   #endif /* !SQLITE_OS_WINRT */
  4543   4543   
  4544   4544     /*
  4545   4545     ** Check to make sure the temporary directory ends with an appropriate
................................................................................
  4723   4723          zUtf8Name[sqlite3Strlen30(zUtf8Name)+1]==0 );
  4724   4724   
  4725   4725     /* Convert the filename to the system encoding. */
  4726   4726     zConverted = winConvertFromUtf8Filename(zUtf8Name);
  4727   4727     if( zConverted==0 ){
  4728   4728       sqlite3_free(zTmpname);
  4729   4729       OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8Name));
  4730         -    return SQLITE_IOERR_NOMEM;
         4730  +    return SQLITE_IOERR_NOMEM_BKPT;
  4731   4731     }
  4732   4732   
  4733   4733     if( winIsDir(zConverted) ){
  4734   4734       sqlite3_free(zConverted);
  4735   4735       sqlite3_free(zTmpname);
  4736   4736       OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8Name));
  4737   4737       return SQLITE_CANTOPEN_ISDIR;
................................................................................
  4923   4923   
  4924   4924     SimulateIOError(return SQLITE_IOERR_DELETE);
  4925   4925     OSTRACE(("DELETE name=%s, syncDir=%d\n", zFilename, syncDir));
  4926   4926   
  4927   4927     zConverted = winConvertFromUtf8Filename(zFilename);
  4928   4928     if( zConverted==0 ){
  4929   4929       OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
  4930         -    return SQLITE_IOERR_NOMEM;
         4930  +    return SQLITE_IOERR_NOMEM_BKPT;
  4931   4931     }
  4932   4932     if( osIsNT() ){
  4933   4933       do {
  4934   4934   #if SQLITE_OS_WINRT
  4935   4935         WIN32_FILE_ATTRIBUTE_DATA sAttrData;
  4936   4936         memset(&sAttrData, 0, sizeof(sAttrData));
  4937   4937         if ( osGetFileAttributesExW(zConverted, GetFileExInfoStandard,
................................................................................
  5031   5031     SimulateIOError( return SQLITE_IOERR_ACCESS; );
  5032   5032     OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
  5033   5033              zFilename, flags, pResOut));
  5034   5034   
  5035   5035     zConverted = winConvertFromUtf8Filename(zFilename);
  5036   5036     if( zConverted==0 ){
  5037   5037       OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
  5038         -    return SQLITE_IOERR_NOMEM;
         5038  +    return SQLITE_IOERR_NOMEM_BKPT;
  5039   5039     }
  5040   5040     if( osIsNT() ){
  5041   5041       int cnt = 0;
  5042   5042       WIN32_FILE_ATTRIBUTE_DATA sAttrData;
  5043   5043       memset(&sAttrData, 0, sizeof(sAttrData));
  5044   5044       while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
  5045   5045                                GetFileExInfoStandard,
................................................................................
  5158   5158       ** NOTE: We are dealing with a relative path name and the data
  5159   5159       **       directory has been set.  Therefore, use it as the basis
  5160   5160       **       for converting the relative path name to an absolute
  5161   5161       **       one by prepending the data directory and a slash.
  5162   5162       */
  5163   5163       char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
  5164   5164       if( !zOut ){
  5165         -      return SQLITE_IOERR_NOMEM;
         5165  +      return SQLITE_IOERR_NOMEM_BKPT;
  5166   5166       }
  5167   5167       if( cygwin_conv_path(
  5168   5168               (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
  5169   5169               CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
  5170   5170         sqlite3_free(zOut);
  5171   5171         return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
  5172   5172                            "winFullPathname1", zRelative);
  5173   5173       }else{
  5174   5174         char *zUtf8 = winConvertToUtf8Filename(zOut);
  5175   5175         if( !zUtf8 ){
  5176   5176           sqlite3_free(zOut);
  5177         -        return SQLITE_IOERR_NOMEM;
         5177  +        return SQLITE_IOERR_NOMEM_BKPT;
  5178   5178         }
  5179   5179         sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
  5180   5180                          sqlite3_data_directory, winGetDirSep(), zUtf8);
  5181   5181         sqlite3_free(zUtf8);
  5182   5182         sqlite3_free(zOut);
  5183   5183       }
  5184   5184     }else{
  5185   5185       char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
  5186   5186       if( !zOut ){
  5187         -      return SQLITE_IOERR_NOMEM;
         5187  +      return SQLITE_IOERR_NOMEM_BKPT;
  5188   5188       }
  5189   5189       if( cygwin_conv_path(
  5190   5190               (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
  5191   5191               zRelative, zOut, pVfs->mxPathname+1)<0 ){
  5192   5192         sqlite3_free(zOut);
  5193   5193         return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
  5194   5194                            "winFullPathname2", zRelative);
  5195   5195       }else{
  5196   5196         char *zUtf8 = winConvertToUtf8Filename(zOut);
  5197   5197         if( !zUtf8 ){
  5198   5198           sqlite3_free(zOut);
  5199         -        return SQLITE_IOERR_NOMEM;
         5199  +        return SQLITE_IOERR_NOMEM_BKPT;
  5200   5200         }
  5201   5201         sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
  5202   5202         sqlite3_free(zUtf8);
  5203   5203         sqlite3_free(zOut);
  5204   5204       }
  5205   5205     }
  5206   5206     return SQLITE_OK;
................................................................................
  5252   5252       */
  5253   5253       sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
  5254   5254                        sqlite3_data_directory, winGetDirSep(), zRelative);
  5255   5255       return SQLITE_OK;
  5256   5256     }
  5257   5257     zConverted = winConvertFromUtf8Filename(zRelative);
  5258   5258     if( zConverted==0 ){
  5259         -    return SQLITE_IOERR_NOMEM;
         5259  +    return SQLITE_IOERR_NOMEM_BKPT;
  5260   5260     }
  5261   5261     if( osIsNT() ){
  5262   5262       LPWSTR zTemp;
  5263   5263       nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
  5264   5264       if( nByte==0 ){
  5265   5265         sqlite3_free(zConverted);
  5266   5266         return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
  5267   5267                            "winFullPathname1", zRelative);
  5268   5268       }
  5269   5269       nByte += 3;
  5270   5270       zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
  5271   5271       if( zTemp==0 ){
  5272   5272         sqlite3_free(zConverted);
  5273         -      return SQLITE_IOERR_NOMEM;
         5273  +      return SQLITE_IOERR_NOMEM_BKPT;
  5274   5274       }
  5275   5275       nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
  5276   5276       if( nByte==0 ){
  5277   5277         sqlite3_free(zConverted);
  5278   5278         sqlite3_free(zTemp);
  5279   5279         return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
  5280   5280                            "winFullPathname2", zRelative);
................................................................................
  5292   5292         return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
  5293   5293                            "winFullPathname3", zRelative);
  5294   5294       }
  5295   5295       nByte += 3;
  5296   5296       zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
  5297   5297       if( zTemp==0 ){
  5298   5298         sqlite3_free(zConverted);
  5299         -      return SQLITE_IOERR_NOMEM;
         5299  +      return SQLITE_IOERR_NOMEM_BKPT;
  5300   5300       }
  5301   5301       nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
  5302   5302       if( nByte==0 ){
  5303   5303         sqlite3_free(zConverted);
  5304   5304         sqlite3_free(zTemp);
  5305   5305         return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
  5306   5306                            "winFullPathname4", zRelative);
................................................................................
  5311   5311     }
  5312   5312   #endif
  5313   5313     if( zOut ){
  5314   5314       sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
  5315   5315       sqlite3_free(zOut);
  5316   5316       return SQLITE_OK;
  5317   5317     }else{
  5318         -    return SQLITE_IOERR_NOMEM;
         5318  +    return SQLITE_IOERR_NOMEM_BKPT;
  5319   5319     }
  5320   5320   #endif
  5321   5321   }
  5322   5322   
  5323   5323   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  5324   5324   /*
  5325   5325   ** Interfaces for opening a shared library, finding entry points

Changes to src/pager.c.

  2320   2320       testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
  2321   2321       assert( !pagerUseWal(pPager) );
  2322   2322       rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
  2323   2323       if( pgno>pPager->dbFileSize ){
  2324   2324         pPager->dbFileSize = pgno;
  2325   2325       }
  2326   2326       if( pPager->pBackup ){
  2327         -      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM);
         2327  +      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
  2328   2328         sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
  2329         -      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM, aData);
         2329  +      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
  2330   2330       }
  2331   2331     }else if( !isMainJrnl && pPg==0 ){
  2332   2332       /* If this is a rollback of a savepoint and data was not written to
  2333   2333       ** the database and the page is not in-memory, there is a potential
  2334   2334       ** problem. When the page is next fetched by the b-tree layer, it 
  2335   2335       ** will be read from the database file, which may or may not be 
  2336   2336       ** current. 
................................................................................
  2394   2394       /* If this was page 1, then restore the value of Pager.dbFileVers.
  2395   2395       ** Do this before any decoding. */
  2396   2396       if( pgno==1 ){
  2397   2397         memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
  2398   2398       }
  2399   2399   
  2400   2400       /* Decode the page just read from disk */
  2401         -    CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM);
         2401  +    CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
  2402   2402       sqlite3PcacheRelease(pPg);
  2403   2403     }
  2404   2404     return rc;
  2405   2405   }
  2406   2406   
  2407   2407   /*
  2408   2408   ** Parameter zMaster is the name of a master journal file. A single journal
................................................................................
  2460   2460   
  2461   2461     /* Allocate space for both the pJournal and pMaster file descriptors.
  2462   2462     ** If successful, open the master journal file for reading.
  2463   2463     */
  2464   2464     pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
  2465   2465     pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile);
  2466   2466     if( !pMaster ){
  2467         -    rc = SQLITE_NOMEM;
         2467  +    rc = SQLITE_NOMEM_BKPT;
  2468   2468     }else{
  2469   2469       const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
  2470   2470       rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
  2471   2471     }
  2472   2472     if( rc!=SQLITE_OK ) goto delmaster_out;
  2473   2473   
  2474   2474     /* Load the entire master journal file into space obtained from
................................................................................
  2477   2477     ** journal files extracted from regular rollback-journals.
  2478   2478     */
  2479   2479     rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
  2480   2480     if( rc!=SQLITE_OK ) goto delmaster_out;
  2481   2481     nMasterPtr = pVfs->mxPathname+1;
  2482   2482     zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
  2483   2483     if( !zMasterJournal ){
  2484         -    rc = SQLITE_NOMEM;
         2484  +    rc = SQLITE_NOMEM_BKPT;
  2485   2485       goto delmaster_out;
  2486   2486     }
  2487   2487     zMasterPtr = &zMasterJournal[nMasterJournal+1];
  2488   2488     rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
  2489   2489     if( rc!=SQLITE_OK ) goto delmaster_out;
  2490   2490     zMasterJournal[nMasterJournal] = 0;
  2491   2491   
................................................................................
  2947   2947         */
  2948   2948         memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
  2949   2949       }else{
  2950   2950         u8 *dbFileVers = &((u8*)pPg->pData)[24];
  2951   2951         memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
  2952   2952       }
  2953   2953     }
  2954         -  CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM);
         2954  +  CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM_BKPT);
  2955   2955   
  2956   2956     PAGER_INCR(sqlite3_pager_readdb_count);
  2957   2957     PAGER_INCR(pPager->nRead);
  2958   2958     IOTRACE(("PGIN %p %d\n", pPager, pgno));
  2959   2959     PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
  2960   2960                  PAGERID(pPager), pgno, pager_pagehash(pPg)));
  2961   2961   
................................................................................
  3307   3307     assert( pPager->eState!=PAGER_ERROR );
  3308   3308     assert( pPager->eState>=PAGER_WRITER_LOCKED );
  3309   3309   
  3310   3310     /* Allocate a bitvec to use to store the set of pages rolled back */
  3311   3311     if( pSavepoint ){
  3312   3312       pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
  3313   3313       if( !pDone ){
  3314         -      return SQLITE_NOMEM;
         3314  +      return SQLITE_NOMEM_BKPT;
  3315   3315       }
  3316   3316     }
  3317   3317   
  3318   3318     /* Set the database size back to the value it was before the savepoint 
  3319   3319     ** being reverted was opened.
  3320   3320     */
  3321   3321     pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
................................................................................
  3670   3670       i64 nByte = 0;
  3671   3671   
  3672   3672       if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
  3673   3673         rc = sqlite3OsFileSize(pPager->fd, &nByte);
  3674   3674       }
  3675   3675       if( rc==SQLITE_OK ){
  3676   3676         pNew = (char *)sqlite3PageMalloc(pageSize);
  3677         -      if( !pNew ) rc = SQLITE_NOMEM;
         3677  +      if( !pNew ) rc = SQLITE_NOMEM_BKPT;
  3678   3678       }
  3679   3679   
  3680   3680       if( rc==SQLITE_OK ){
  3681   3681         pager_reset(pPager);
  3682   3682         rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
  3683   3683       }
  3684   3684       if( rc==SQLITE_OK ){
................................................................................
  3946   3946       pPager->pMmapFreelist = p->pDirty;
  3947   3947       p->pDirty = 0;
  3948   3948       memset(p->pExtra, 0, pPager->nExtra);
  3949   3949     }else{
  3950   3950       *ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
  3951   3951       if( p==0 ){
  3952   3952         sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
  3953         -      return SQLITE_NOMEM;
         3953  +      return SQLITE_NOMEM_BKPT;
  3954   3954       }
  3955   3955       p->pExtra = (void *)&p[1];
  3956   3956       p->flags = PGHDR_MMAP;
  3957   3957       p->nRef = 1;
  3958   3958       p->pPager = pPager;
  3959   3959     }
  3960   3960   
................................................................................
  4304   4304         i64 offset = (pgno-1)*(i64)pPager->pageSize;   /* Offset to write */
  4305   4305         char *pData;                                   /* Data to write */    
  4306   4306   
  4307   4307         assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
  4308   4308         if( pList->pgno==1 ) pager_write_changecounter(pList);
  4309   4309   
  4310   4310         /* Encode the database */
  4311         -      CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
         4311  +      CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM_BKPT, pData);
  4312   4312   
  4313   4313         /* Write out the page data. */
  4314   4314         rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
  4315   4315   
  4316   4316         /* If page 1 was just written, update Pager.dbFileVers to match
  4317   4317         ** the value now stored in the database file. If writing this 
  4318   4318         ** page caused the database file to grow, update dbFileSize. 
................................................................................
  4391   4391       /* If the sub-journal was opened successfully (or was already open),
  4392   4392       ** write the journal record into the file.  */
  4393   4393       if( rc==SQLITE_OK ){
  4394   4394         void *pData = pPg->pData;
  4395   4395         i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
  4396   4396         char *pData2;
  4397   4397     
  4398         -      CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
         4398  +      CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
  4399   4399         PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
  4400   4400         rc = write32bits(pPager->sjfd, offset, pPg->pgno);
  4401   4401         if( rc==SQLITE_OK ){
  4402   4402           rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
  4403   4403         }
  4404   4404       }
  4405   4405     }
................................................................................
  4595   4595     *ppPager = 0;
  4596   4596   
  4597   4597   #ifndef SQLITE_OMIT_MEMORYDB
  4598   4598     if( flags & PAGER_MEMORY ){
  4599   4599       memDb = 1;
  4600   4600       if( zFilename && zFilename[0] ){
  4601   4601         zPathname = sqlite3DbStrDup(0, zFilename);
  4602         -      if( zPathname==0  ) return SQLITE_NOMEM;
         4602  +      if( zPathname==0  ) return SQLITE_NOMEM_BKPT;
  4603   4603         nPathname = sqlite3Strlen30(zPathname);
  4604   4604         zFilename = 0;
  4605   4605       }
  4606   4606     }
  4607   4607   #endif
  4608   4608   
  4609   4609     /* Compute and store the full pathname in an allocated buffer pointed
................................................................................
  4611   4611     ** leave both nPathname and zPathname set to 0.
  4612   4612     */
  4613   4613     if( zFilename && zFilename[0] ){
  4614   4614       const char *z;
  4615   4615       nPathname = pVfs->mxPathname+1;
  4616   4616       zPathname = sqlite3DbMallocRaw(0, nPathname*2);
  4617   4617       if( zPathname==0 ){
  4618         -      return SQLITE_NOMEM;
         4618  +      return SQLITE_NOMEM_BKPT;
  4619   4619       }
  4620   4620       zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
  4621   4621       rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
  4622   4622       nPathname = sqlite3Strlen30(zPathname);
  4623   4623       z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
  4624   4624       while( *z ){
  4625   4625         z += sqlite3Strlen30(z)+1;
................................................................................
  4664   4664   #ifndef SQLITE_OMIT_WAL
  4665   4665       + nPathname + 4 + 2            /* zWal */
  4666   4666   #endif
  4667   4667     );
  4668   4668     assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
  4669   4669     if( !pPtr ){
  4670   4670       sqlite3DbFree(0, zPathname);
  4671         -    return SQLITE_NOMEM;
         4671  +    return SQLITE_NOMEM_BKPT;
  4672   4672     }
  4673   4673     pPager =              (Pager*)(pPtr);
  4674   4674     pPager->pPCache =    (PCache*)(pPtr += ROUND8(sizeof(*pPager)));
  4675   4675     pPager->fd =   (sqlite3_file*)(pPtr += ROUND8(pcacheSize));
  4676   4676     pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile));
  4677   4677     pPager->jfd =  (sqlite3_file*)(pPtr += journalFileSize);
  4678   4678     pPager->zFilename =    (char*)(pPtr += journalFileSize);
................................................................................
  5384   5384         sqlite3_pcache_page *pBase;
  5385   5385         pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
  5386   5386         if( pBase==0 ){
  5387   5387           rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
  5388   5388           if( rc!=SQLITE_OK ) goto pager_acquire_err;
  5389   5389           if( pBase==0 ){
  5390   5390             pPg = *ppPage = 0;
  5391         -          rc = SQLITE_NOMEM;
         5391  +          rc = SQLITE_NOMEM_BKPT;
  5392   5392             goto pager_acquire_err;
  5393   5393           }
  5394   5394         }
  5395   5395         pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
  5396   5396         assert( pPg!=0 );
  5397   5397       }
  5398   5398     }
................................................................................
  5558   5558     ** the other hand, this routine is never called if we are already in
  5559   5559     ** an error state. */
  5560   5560     if( NEVER(pPager->errCode) ) return pPager->errCode;
  5561   5561   
  5562   5562     if( !pagerUseWal(pPager) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
  5563   5563       pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
  5564   5564       if( pPager->pInJournal==0 ){
  5565         -      return SQLITE_NOMEM;
         5565  +      return SQLITE_NOMEM_BKPT;
  5566   5566       }
  5567   5567     
  5568   5568       /* Open the journal file if it is not already open. */
  5569   5569       if( !isOpen(pPager->jfd) ){
  5570   5570         if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
  5571   5571           sqlite3MemJournalOpen(pPager->jfd);
  5572   5572         }else{
................................................................................
  5713   5713   
  5714   5714     /* We should never write to the journal file the page that
  5715   5715     ** contains the database locks.  The following assert verifies
  5716   5716     ** that we do not. */
  5717   5717     assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
  5718   5718   
  5719   5719     assert( pPager->journalHdr<=pPager->journalOff );
  5720         -  CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
         5720  +  CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
  5721   5721     cksum = pager_cksum(pPager, (u8*)pData2);
  5722   5722   
  5723   5723     /* Even if an IO or diskfull error occurs while journalling the
  5724   5724     ** page in the block above, set the need-sync flag for the page.
  5725   5725     ** Otherwise, when the transaction is rolled back, the logic in
  5726   5726     ** playback_one_page() will think that the page needs to be restored
  5727   5727     ** in the database file. And if an IO error occurs while doing so,
................................................................................
  6070   6070         /* Actually do the update of the change counter */
  6071   6071         pager_write_changecounter(pPgHdr);
  6072   6072   
  6073   6073         /* If running in direct mode, write the contents of page 1 to the file. */
  6074   6074         if( DIRECT_MODE ){
  6075   6075           const void *zBuf;
  6076   6076           assert( pPager->dbFileSize>0 );
  6077         -        CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf);
         6077  +        CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM_BKPT, zBuf);
  6078   6078           if( rc==SQLITE_OK ){
  6079   6079             rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
  6080   6080             pPager->aStat[PAGER_STAT_WRITE]++;
  6081   6081           }
  6082   6082           if( rc==SQLITE_OK ){
  6083   6083             /* Update the pager's copy of the change-counter. Otherwise, the
  6084   6084             ** next time a read transaction is opened the cache will be
................................................................................
  6569   6569     ** if the allocation fails. Otherwise, zero the new portion in case a 
  6570   6570     ** malloc failure occurs while populating it in the for(...) loop below.
  6571   6571     */
  6572   6572     aNew = (PagerSavepoint *)sqlite3Realloc(
  6573   6573         pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
  6574   6574     );
  6575   6575     if( !aNew ){
  6576         -    return SQLITE_NOMEM;
         6576  +    return SQLITE_NOMEM_BKPT;
  6577   6577     }
  6578   6578     memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
  6579   6579     pPager->aSavepoint = aNew;
  6580   6580   
  6581   6581     /* Populate the PagerSavepoint structures just allocated. */
  6582   6582     for(ii=nCurrent; ii<nSavepoint; ii++){
  6583   6583       aNew[ii].nOrig = pPager->dbSize;
................................................................................
  6585   6585         aNew[ii].iOffset = pPager->journalOff;
  6586   6586       }else{
  6587   6587         aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
  6588   6588       }
  6589   6589       aNew[ii].iSubRec = pPager->nSubRec;
  6590   6590       aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
  6591   6591       if( !aNew[ii].pInSavepoint ){
  6592         -      return SQLITE_NOMEM;
         6592  +      return SQLITE_NOMEM_BKPT;
  6593   6593       }
  6594   6594       if( pagerUseWal(pPager) ){
  6595   6595         sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData);
  6596   6596       }
  6597   6597       pPager->nSavepoint = ii+1;
  6598   6598     }
  6599   6599     assert( pPager->nSavepoint==nSavepoint );

Changes to src/pcache.c.

   187    187     assert( pCache->nRefSum==0 && pCache->pDirty==0 );
   188    188     if( pCache->szPage ){
   189    189       sqlite3_pcache *pNew;
   190    190       pNew = sqlite3GlobalConfig.pcache2.xCreate(
   191    191                   szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
   192    192                   pCache->bPurgeable
   193    193       );
   194         -    if( pNew==0 ) return SQLITE_NOMEM;
          194  +    if( pNew==0 ) return SQLITE_NOMEM_BKPT;
   195    195       sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
   196    196       if( pCache->pCache ){
   197    197         sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
   198    198       }
   199    199       pCache->pCache = pNew;
   200    200       pCache->szPage = szPage;
   201    201     }
................................................................................
   297    297         rc = pCache->xStress(pCache->pStress, pPg);
   298    298         if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
   299    299           return rc;
   300    300         }
   301    301       }
   302    302     }
   303    303     *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
   304         -  return *ppPage==0 ? SQLITE_NOMEM : SQLITE_OK;
          304  +  return *ppPage==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
   305    305   }
   306    306   
   307    307   /*
   308    308   ** This is a helper routine for sqlite3PcacheFetchFinish()
   309    309   **
   310    310   ** In the uncommon case where the page being fetched has not been
   311    311   ** initialized, this routine is invoked to do the initialization.

Changes to src/prepare.c.

    29     29       char *z;
    30     30       if( zObj==0 ) zObj = "?";
    31     31       z = sqlite3MPrintf(db, "malformed database schema (%s)", zObj);
    32     32       if( zExtra ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
    33     33       sqlite3DbFree(db, *pData->pzErrMsg);
    34     34       *pData->pzErrMsg = z;
    35     35     }
    36         -  pData->rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_CORRUPT_BKPT;
           36  +  pData->rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_CORRUPT_BKPT;
    37     37   }
    38     38   
    39     39   /*
    40     40   ** This is the callback routine for the code that initializes the
    41     41   ** database.  See sqlite3Init() below for additional information.
    42     42   ** This routine is also called from the OP_ParseSchema opcode of the VDBE.
    43     43   **
................................................................................
   303    303   #ifndef SQLITE_OMIT_ANALYZE
   304    304       if( rc==SQLITE_OK ){
   305    305         sqlite3AnalysisLoad(db, iDb);
   306    306       }
   307    307   #endif
   308    308     }
   309    309     if( db->mallocFailed ){
   310         -    rc = SQLITE_NOMEM;
          310  +    rc = SQLITE_NOMEM_BKPT;
   311    311       sqlite3ResetAllSchemasOfConnection(db);
   312    312     }
   313    313     if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){
   314    314       /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider
   315    315       ** the schema loaded, even if errors occurred. In this situation the 
   316    316       ** current sqlite3_prepare() operation will fail, but the following one
   317    317       ** will attempt to compile the supplied statement against whatever subset
................................................................................
   520    520     char *zErrMsg = 0;        /* Error message */
   521    521     int rc = SQLITE_OK;       /* Result code */
   522    522     int i;                    /* Loop counter */
   523    523   
   524    524     /* Allocate the parsing context */
   525    525     pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
   526    526     if( pParse==0 ){
   527         -    rc = SQLITE_NOMEM;
          527  +    rc = SQLITE_NOMEM_BKPT;
   528    528       goto end_prepare;
   529    529     }
   530    530     pParse->pReprepare = pReprepare;
   531    531     assert( ppStmt && *ppStmt==0 );
   532    532     /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
   533    533     assert( sqlite3_mutex_held(db->mutex) );
   534    534   
................................................................................
   597    597     assert( 0==pParse->nQueryLoop );
   598    598   
   599    599     if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
   600    600     if( pParse->checkSchema ){
   601    601       schemaIsValid(pParse);
   602    602     }
   603    603     if( db->mallocFailed ){
   604         -    pParse->rc = SQLITE_NOMEM;
          604  +    pParse->rc = SQLITE_NOMEM_BKPT;
   605    605     }
   606    606     if( pzTail ){
   607    607       *pzTail = pParse->zTail;
   608    608     }
   609    609     rc = pParse->rc;
   610    610   
   611    611   #ifndef SQLITE_OMIT_EXPLAIN

Changes to src/select.c.

  1684   1684     if( db->mallocFailed ){
  1685   1685       for(j=0; j<i; j++){
  1686   1686         sqlite3DbFree(db, aCol[j].zName);
  1687   1687       }
  1688   1688       sqlite3DbFree(db, aCol);
  1689   1689       *paCol = 0;
  1690   1690       *pnCol = 0;
  1691         -    return SQLITE_NOMEM;
         1691  +    return SQLITE_NOMEM_BKPT;
  1692   1692     }
  1693   1693     return SQLITE_OK;
  1694   1694   }
  1695   1695   
  1696   1696   /*
  1697   1697   ** Add type and collation information to a column list based on
  1698   1698   ** a SELECT statement.
................................................................................
  2495   2495       CollSeq **apColl;             /* For looping through pKeyInfo->aColl[] */
  2496   2496       int nCol;                     /* Number of columns in result set */
  2497   2497   
  2498   2498       assert( p->pNext==0 );
  2499   2499       nCol = p->pEList->nExpr;
  2500   2500       pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
  2501   2501       if( !pKeyInfo ){
  2502         -      rc = SQLITE_NOMEM;
         2502  +      rc = SQLITE_NOMEM_BKPT;
  2503   2503         goto multi_select_end;
  2504   2504       }
  2505   2505       for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
  2506   2506         *apColl = multiSelectCollSeq(pParse, p, i);
  2507   2507         if( 0==*apColl ){
  2508   2508           *apColl = db->pDfltColl;
  2509   2509         }
................................................................................
  2850   2850         struct ExprList_item *pItem;
  2851   2851         for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
  2852   2852           assert( pItem->u.x.iOrderByCol>0 );
  2853   2853           if( pItem->u.x.iOrderByCol==i ) break;
  2854   2854         }
  2855   2855         if( j==nOrderBy ){
  2856   2856           Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
  2857         -        if( pNew==0 ) return SQLITE_NOMEM;
         2857  +        if( pNew==0 ) return SQLITE_NOMEM_BKPT;
  2858   2858           pNew->flags |= EP_IntValue;
  2859   2859           pNew->u.iValue = i;
  2860   2860           pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
  2861   2861           if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
  2862   2862         }
  2863   2863       }
  2864   2864     }
................................................................................
  4087   4087       if( pTab==0 ) return WRC_Abort;
  4088   4088       pTab->nRef = 1;
  4089   4089       pTab->zName = sqlite3DbStrDup(db, pCte->zName);
  4090   4090       pTab->iPKey = -1;
  4091   4091       pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
  4092   4092       pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
  4093   4093       pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
  4094         -    if( db->mallocFailed ) return SQLITE_NOMEM;
         4094  +    if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
  4095   4095       assert( pFrom->pSelect );
  4096   4096   
  4097   4097       /* Check if this is a recursive CTE. */
  4098   4098       pSel = pFrom->pSelect;
  4099   4099       bMayRecursive = ( pSel->op==TK_ALL || pSel->op==TK_UNION );
  4100   4100       if( bMayRecursive ){
  4101   4101         int i;

Changes to src/sqliteInt.h.

  3162   3162   ** routines that report the line-number on which the error originated
  3163   3163   ** using sqlite3_log().  The routines also provide a convenient place
  3164   3164   ** to set a debugger breakpoint.
  3165   3165   */
  3166   3166   int sqlite3CorruptError(int);
  3167   3167   int sqlite3MisuseError(int);
  3168   3168   int sqlite3CantopenError(int);
         3169  +int sqlite3NomemError(int);
         3170  +int sqlite3IoerrnomemError(int);
  3169   3171   #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__)
  3170   3172   #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__)
  3171   3173   #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__)
         3174  +#define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__)
         3175  +#define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__)
  3172   3176   
  3173   3177   /*
  3174   3178   ** FTS3 and FTS4 both require virtual table support
  3175   3179   */
  3176   3180   #if defined(SQLITE_OMIT_VIRTUALTABLE)
  3177   3181   # undef SQLITE_ENABLE_FTS3
  3178   3182   # undef SQLITE_ENABLE_FTS4

Changes to src/table.c.

    97     97         p->azResult[p->nData++] = z;
    98     98       }
    99     99       p->nRow++;
   100    100     }
   101    101     return 0;
   102    102   
   103    103   malloc_failed:
   104         -  p->rc = SQLITE_NOMEM;
          104  +  p->rc = SQLITE_NOMEM_BKPT;
   105    105     return 1;
   106    106   }
   107    107   
   108    108   /*
   109    109   ** Query the database.  But instead of invoking a callback for each row,
   110    110   ** malloc() for space to hold the result and return the entire results
   111    111   ** at the conclusion of the call.
................................................................................
   138    138     res.nColumn = 0;
   139    139     res.nData = 1;
   140    140     res.nAlloc = 20;
   141    141     res.rc = SQLITE_OK;
   142    142     res.azResult = sqlite3_malloc64(sizeof(char*)*res.nAlloc );
   143    143     if( res.azResult==0 ){
   144    144        db->errCode = SQLITE_NOMEM;
   145         -     return SQLITE_NOMEM;
          145  +     return SQLITE_NOMEM_BKPT;
   146    146     }
   147    147     res.azResult[0] = 0;
   148    148     rc = sqlite3_exec(db, zSql, sqlite3_get_table_cb, &res, pzErrMsg);
   149    149     assert( sizeof(res.azResult[0])>= sizeof(res.nData) );
   150    150     res.azResult[0] = SQLITE_INT_TO_PTR(res.nData);
   151    151     if( (rc&0xff)==SQLITE_ABORT ){
   152    152       sqlite3_free_table(&res.azResult[1]);
................................................................................
   167    167     }
   168    168     if( res.nAlloc>res.nData ){
   169    169       char **azNew;
   170    170       azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData );
   171    171       if( azNew==0 ){
   172    172         sqlite3_free_table(&res.azResult[1]);
   173    173         db->errCode = SQLITE_NOMEM;
   174         -      return SQLITE_NOMEM;
          174  +      return SQLITE_NOMEM_BKPT;
   175    175       }
   176    176       res.azResult = azNew;
   177    177     }
   178    178     *pazResult = &res.azResult[1];
   179    179     if( pnColumn ) *pnColumn = res.nColumn;
   180    180     if( pnRow ) *pnRow = res.nRow;
   181    181     return rc;

Changes to src/threads.c.

    59     59     assert( ppThread!=0 );
    60     60     assert( xTask!=0 );
    61     61     /* This routine is never used in single-threaded mode */
    62     62     assert( sqlite3GlobalConfig.bCoreMutex!=0 );
    63     63   
    64     64     *ppThread = 0;
    65     65     p = sqlite3Malloc(sizeof(*p));
    66         -  if( p==0 ) return SQLITE_NOMEM;
           66  +  if( p==0 ) return SQLITE_NOMEM_BKPT;
    67     67     memset(p, 0, sizeof(*p));
    68     68     p->xTask = xTask;
    69     69     p->pIn = pIn;
    70     70     /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a 
    71     71     ** function that returns SQLITE_ERROR when passed the argument 200, that
    72     72     ** forces worker threads to run sequentially and deterministically 
    73     73     ** for testing purposes. */
................................................................................
    85     85   }
    86     86   
    87     87   /* Get the results of the thread */
    88     88   int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
    89     89     int rc;
    90     90   
    91     91     assert( ppOut!=0 );
    92         -  if( NEVER(p==0) ) return SQLITE_NOMEM;
           92  +  if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT;
    93     93     if( p->done ){
    94     94       *ppOut = p->pOut;
    95     95       rc = SQLITE_OK;
    96     96     }else{
    97     97       rc = pthread_join(p->tid, ppOut) ? SQLITE_ERROR : SQLITE_OK;
    98     98     }
    99     99     sqlite3_free(p);
................................................................................
   150    150   ){
   151    151     SQLiteThread *p;
   152    152   
   153    153     assert( ppThread!=0 );
   154    154     assert( xTask!=0 );
   155    155     *ppThread = 0;
   156    156     p = sqlite3Malloc(sizeof(*p));
   157         -  if( p==0 ) return SQLITE_NOMEM;
          157  +  if( p==0 ) return SQLITE_NOMEM_BKPT;
   158    158     /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a 
   159    159     ** function that returns SQLITE_ERROR when passed the argument 200, that
   160    160     ** forces worker threads to run sequentially and deterministically 
   161    161     ** (via the sqlite3FaultSim() term of the conditional) for testing
   162    162     ** purposes. */
   163    163     if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){
   164    164       memset(p, 0, sizeof(*p));
................................................................................
   182    182   
   183    183   /* Get the results of the thread */
   184    184   int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
   185    185     DWORD rc;
   186    186     BOOL bRc;
   187    187   
   188    188     assert( ppOut!=0 );
   189         -  if( NEVER(p==0) ) return SQLITE_NOMEM;
          189  +  if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT;
   190    190     if( p->xTask==0 ){
   191    191       /* assert( p->id==GetCurrentThreadId() ); */
   192    192       rc = WAIT_OBJECT_0;
   193    193       assert( p->tid==0 );
   194    194     }else{
   195    195       assert( p->id!=0 && p->id!=GetCurrentThreadId() );
   196    196       rc = sqlite3Win32Wait((HANDLE)p->tid);
................................................................................
   230    230   ){
   231    231     SQLiteThread *p;
   232    232   
   233    233     assert( ppThread!=0 );
   234    234     assert( xTask!=0 );
   235    235     *ppThread = 0;
   236    236     p = sqlite3Malloc(sizeof(*p));
   237         -  if( p==0 ) return SQLITE_NOMEM;
          237  +  if( p==0 ) return SQLITE_NOMEM_BKPT;
   238    238     if( (SQLITE_PTR_TO_INT(p)/17)&1 ){
   239    239       p->xTask = xTask;
   240    240       p->pIn = pIn;
   241    241     }else{
   242    242       p->xTask = 0;
   243    243       p->pResult = xTask(pIn);
   244    244     }
................................................................................
   246    246     return SQLITE_OK;
   247    247   }
   248    248   
   249    249   /* Get the results of the thread */
   250    250   int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){
   251    251   
   252    252     assert( ppOut!=0 );
   253         -  if( NEVER(p==0) ) return SQLITE_NOMEM;
          253  +  if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT;
   254    254     if( p->xTask ){
   255    255       *ppOut = p->xTask(p->pIn);
   256    256     }else{
   257    257       *ppOut = p->pResult;
   258    258     }
   259    259     sqlite3_free(p);
   260    260   
   261    261   #if defined(SQLITE_TEST)
   262    262     {
   263    263       void *pTstAlloc = sqlite3Malloc(10);
   264         -    if (!pTstAlloc) return SQLITE_NOMEM;
          264  +    if (!pTstAlloc) return SQLITE_NOMEM_BKPT;
   265    265       sqlite3_free(pTstAlloc);
   266    266     }
   267    267   #endif
   268    268   
   269    269     return SQLITE_OK;
   270    270   }
   271    271   
   272    272   #endif /* !defined(SQLITE_THREADS_IMPLEMENTED) */
   273    273   /****************************** End Single-Threaded *************************/
   274    274   #endif /* SQLITE_MAX_WORKER_THREADS>0 */

Changes to src/tokenize.c.

   491    491     pParse->zTail = zSql;
   492    492     i = 0;
   493    493     assert( pzErrMsg!=0 );
   494    494     /* sqlite3ParserTrace(stdout, "parser: "); */
   495    495     pEngine = sqlite3ParserAlloc(sqlite3Malloc);
   496    496     if( pEngine==0 ){
   497    497       sqlite3OomFault(db);
   498         -    return SQLITE_NOMEM;
          498  +    return SQLITE_NOMEM_BKPT;
   499    499     }
   500    500     assert( pParse->pNewTable==0 );
   501    501     assert( pParse->pNewTrigger==0 );
   502    502     assert( pParse->nVar==0 );
   503    503     assert( pParse->nzVar==0 );
   504    504     assert( pParse->azVar==0 );
   505    505     while( zSql[i]!=0 ){
................................................................................
   545    545     sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
   546    546         sqlite3ParserStackPeak(pEngine)
   547    547     );
   548    548     sqlite3_mutex_leave(sqlite3MallocMutex());
   549    549   #endif /* YYDEBUG */
   550    550     sqlite3ParserFree(pEngine, sqlite3_free);
   551    551     if( db->mallocFailed ){
   552         -    pParse->rc = SQLITE_NOMEM;
          552  +    pParse->rc = SQLITE_NOMEM_BKPT;
   553    553     }
   554    554     if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
   555    555       pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
   556    556     }
   557    557     assert( pzErrMsg!=0 );
   558    558     if( pParse->zErrMsg ){
   559    559       *pzErrMsg = pParse->zErrMsg;

Changes to src/utf.c.

   227    227     */
   228    228     if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
   229    229       u8 temp;
   230    230       int rc;
   231    231       rc = sqlite3VdbeMemMakeWriteable(pMem);
   232    232       if( rc!=SQLITE_OK ){
   233    233         assert( rc==SQLITE_NOMEM );
   234         -      return SQLITE_NOMEM;
          234  +      return SQLITE_NOMEM_BKPT;
   235    235       }
   236    236       zIn = (u8*)pMem->z;
   237    237       zTerm = &zIn[pMem->n&~1];
   238    238       while( zIn<zTerm ){
   239    239         temp = *zIn;
   240    240         *zIn = *(zIn+1);
   241    241         zIn++;
................................................................................
   269    269     ** Variable zOut is set to point at the output buffer, space obtained
   270    270     ** from sqlite3_malloc().
   271    271     */
   272    272     zIn = (u8*)pMem->z;
   273    273     zTerm = &zIn[pMem->n];
   274    274     zOut = sqlite3DbMallocRaw(pMem->db, len);
   275    275     if( !zOut ){
   276         -    return SQLITE_NOMEM;
          276  +    return SQLITE_NOMEM_BKPT;
   277    277     }
   278    278     z = zOut;
   279    279   
   280    280     if( pMem->enc==SQLITE_UTF8 ){
   281    281       if( desiredEnc==SQLITE_UTF16LE ){
   282    282         /* UTF-8 -> UTF-16 Little-endian */
   283    283         while( zIn<zTerm ){

Changes to src/vacuum.c.

    34     34   /*
    35     35   ** Execute zSql on database db. Return an error code.
    36     36   */
    37     37   static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
    38     38     sqlite3_stmt *pStmt;
    39     39     VVA_ONLY( int rc; )
    40     40     if( !zSql ){
    41         -    return SQLITE_NOMEM;
           41  +    return SQLITE_NOMEM_BKPT;
    42     42     }
    43     43     if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
    44     44       sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
    45     45       return sqlite3_errcode(db);
    46     46     }
    47     47     VVA_ONLY( rc = ) sqlite3_step(pStmt);
    48     48     assert( rc!=SQLITE_ROW || (db->flags&SQLITE_CountRows) );
................................................................................
   215    215       db->nextPagesize = 0;
   216    216     }
   217    217   
   218    218     if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0)
   219    219      || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0))
   220    220      || NEVER(db->mallocFailed)
   221    221     ){
   222         -    rc = SQLITE_NOMEM;
          222  +    rc = SQLITE_NOMEM_BKPT;
   223    223       goto end_of_vacuum;
   224    224     }
   225    225   
   226    226   #ifndef SQLITE_OMIT_AUTOVACUUM
   227    227     sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac :
   228    228                                              sqlite3BtreeGetAutoVacuum(pMain));
   229    229   #endif

Changes to src/vdbe.c.

  5311   5311       initData.db = db;
  5312   5312       initData.iDb = pOp->p1;
  5313   5313       initData.pzErrMsg = &p->zErrMsg;
  5314   5314       zSql = sqlite3MPrintf(db,
  5315   5315          "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
  5316   5316          db->aDb[iDb].zName, zMaster, pOp->p4.z);
  5317   5317       if( zSql==0 ){
  5318         -      rc = SQLITE_NOMEM;
         5318  +      rc = SQLITE_NOMEM_BKPT;
  5319   5319       }else{
  5320   5320         assert( db->init.busy==0 );
  5321   5321         db->init.busy = 1;
  5322   5322         initData.rc = SQLITE_OK;
  5323   5323         assert( !db->mallocFailed );
  5324   5324         rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
  5325   5325         if( rc==SQLITE_OK ) rc = initData.rc;
................................................................................
  6812   6812     goto vdbe_error_halt;
  6813   6813   
  6814   6814     /* Jump to here if a malloc() fails.
  6815   6815     */
  6816   6816   no_mem:
  6817   6817     sqlite3OomFault(db);
  6818   6818     sqlite3VdbeError(p, "out of memory");
  6819         -  rc = SQLITE_NOMEM;
         6819  +  rc = SQLITE_NOMEM_BKPT;
  6820   6820     goto vdbe_error_halt;
  6821   6821   
  6822   6822     /* Jump to here for any other kind of fatal error.  The "rc" variable
  6823   6823     ** should hold the error number.
  6824   6824     */
  6825   6825   abort_due_to_error:
  6826   6826     assert( p->zErrMsg==0 );
  6827         -  if( db->mallocFailed ) rc = SQLITE_NOMEM;
         6827  +  if( db->mallocFailed ) rc = SQLITE_NOMEM_BKPT;
  6828   6828     if( rc!=SQLITE_IOERR_NOMEM ){
  6829   6829       sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
  6830   6830     }
  6831   6831     goto vdbe_error_halt;
  6832   6832   
  6833   6833     /* Jump to here if the sqlite3_interrupt() API sets the interrupt
  6834   6834     ** flag.
  6835   6835     */
  6836   6836   abort_due_to_interrupt:
  6837   6837     assert( db->u1.isInterrupted );
  6838         -  rc = db->mallocFailed ? SQLITE_NOMEM : SQLITE_INTERRUPT;
         6838  +  rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
  6839   6839     p->rc = rc;
  6840   6840     sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
  6841   6841     goto vdbe_error_halt;
  6842   6842   }

Changes to src/vdbeapi.c.

   467    467                          SQLITE_UTF8, SQLITE_STATIC);
   468    468   }
   469    469   
   470    470   /* An SQLITE_NOMEM error. */
   471    471   void sqlite3_result_error_nomem(sqlite3_context *pCtx){
   472    472     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
   473    473     sqlite3VdbeMemSetNull(pCtx->pOut);
   474         -  pCtx->isError = SQLITE_NOMEM;
          474  +  pCtx->isError = SQLITE_NOMEM_BKPT;
   475    475     pCtx->fErrorOrAux = 1;
   476    476     sqlite3OomFault(pCtx->pOut->db);
   477    477   }
   478    478   
   479    479   /*
   480    480   ** This function is called after a transaction has been committed. It 
   481    481   ** invokes callbacks registered with sqlite3_wal_hook() as required.
................................................................................
   543    543   #endif
   544    544     }
   545    545   
   546    546     /* Check that malloc() has not failed. If it has, return early. */
   547    547     db = p->db;
   548    548     if( db->mallocFailed ){
   549    549       p->rc = SQLITE_NOMEM;
   550         -    return SQLITE_NOMEM;
          550  +    return SQLITE_NOMEM_BKPT;
   551    551     }
   552    552   
   553    553     if( p->pc<=0 && p->expired ){
   554    554       p->rc = SQLITE_SCHEMA;
   555    555       rc = SQLITE_ERROR;
   556    556       goto end_of_step;
   557    557     }
................................................................................
   606    606       if( p->rc!=SQLITE_OK ){
   607    607         rc = SQLITE_ERROR;
   608    608       }
   609    609     }
   610    610   
   611    611     db->errCode = rc;
   612    612     if( SQLITE_NOMEM==sqlite3ApiExit(p->db, p->rc) ){
   613         -    p->rc = SQLITE_NOMEM;
          613  +    p->rc = SQLITE_NOMEM_BKPT;
   614    614     }
   615    615   end_of_step:
   616    616     /* At this point local variable rc holds the value that should be 
   617    617     ** returned if this statement was compiled using the legacy 
   618    618     ** sqlite3_prepare() interface. According to the docs, this can only
   619    619     ** be one of the values in the first assert() below. Variable p->rc 
   620    620     ** contains the value that would be returned if sqlite3_finalize() 
................................................................................
   673    673       const char *zErr = (const char *)sqlite3_value_text(db->pErr); 
   674    674       sqlite3DbFree(db, v->zErrMsg);
   675    675       if( !db->mallocFailed ){
   676    676         v->zErrMsg = sqlite3DbStrDup(db, zErr);
   677    677         v->rc = rc2;
   678    678       } else {
   679    679         v->zErrMsg = 0;
   680         -      v->rc = rc = SQLITE_NOMEM;
          680  +      v->rc = rc = SQLITE_NOMEM_BKPT;
   681    681       }
   682    682     }
   683    683     rc = sqlite3ApiExit(db, rc);
   684    684     sqlite3_mutex_leave(db->mutex);
   685    685     return rc;
   686    686   }
   687    687   

Changes to src/vdbeaux.c.

   125    125     assert( nNew>=(p->nOpAlloc+nOp) );
   126    126     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   127    127     if( pNew ){
   128    128       p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
   129    129       p->nOpAlloc = p->szOpAlloc/sizeof(Op);
   130    130       v->aOp = pNew;
   131    131     }
   132         -  return (pNew ? SQLITE_OK : SQLITE_NOMEM);
          132  +  return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
   133    133   }
   134    134   
   135    135   #ifdef SQLITE_DEBUG
   136    136   /* This routine is just a convenient place to set a breakpoint that will
   137    137   ** fire after each opcode is inserted and displayed using
   138    138   ** "PRAGMA vdbe_addoptrace=on".
   139    139   */
................................................................................
  1526   1526     /* Even though this opcode does not use dynamic strings for
  1527   1527     ** the result, result columns may become dynamic if the user calls
  1528   1528     ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
  1529   1529     */
  1530   1530     releaseMemArray(pMem, 8);
  1531   1531     p->pResultSet = 0;
  1532   1532   
  1533         -  if( p->rc==SQLITE_NOMEM ){
         1533  +  if( p->rc==SQLITE_NOMEM_BKPT ){
  1534   1534       /* This happens if a malloc() inside a call to sqlite3_column_text() or
  1535   1535       ** sqlite3_column_text16() failed.  */
  1536   1536       sqlite3OomFault(db);
  1537   1537       return SQLITE_ERROR;
  1538   1538     }
  1539   1539   
  1540   1540     /* When the number of output rows reaches nRow, that means the
................................................................................
  2115   2115   ){
  2116   2116     int rc;
  2117   2117     Mem *pColName;
  2118   2118     assert( idx<p->nResColumn );
  2119   2119     assert( var<COLNAME_N );
  2120   2120     if( p->db->mallocFailed ){
  2121   2121       assert( !zName || xDel!=SQLITE_DYNAMIC );
  2122         -    return SQLITE_NOMEM;
         2122  +    return SQLITE_NOMEM_BKPT;
  2123   2123     }
  2124   2124     assert( p->aColName!=0 );
  2125   2125     pColName = &(p->aColName[idx+var*p->nResColumn]);
  2126   2126     rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, xDel);
  2127   2127     assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
  2128   2128     return rc;
  2129   2129   }
................................................................................
  2233   2233       int res;
  2234   2234       int retryCount = 0;
  2235   2235       int nMainFile;
  2236   2236   
  2237   2237       /* Select a master journal file name */
  2238   2238       nMainFile = sqlite3Strlen30(zMainFile);
  2239   2239       zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz", zMainFile);
  2240         -    if( zMaster==0 ) return SQLITE_NOMEM;
         2240  +    if( zMaster==0 ) return SQLITE_NOMEM_BKPT;
  2241   2241       do {
  2242   2242         u32 iRandom;
  2243   2243         if( retryCount ){
  2244   2244           if( retryCount>100 ){
  2245   2245             sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster);
  2246   2246             sqlite3OsDelete(pVfs, zMaster, 0);
  2247   2247             break;
................................................................................
  2523   2523     **
  2524   2524     ** Then the internal cache might have been left in an inconsistent
  2525   2525     ** state.  We need to rollback the statement transaction, if there is
  2526   2526     ** one, or the complete transaction if there is no statement transaction.
  2527   2527     */
  2528   2528   
  2529   2529     if( db->mallocFailed ){
  2530         -    p->rc = SQLITE_NOMEM;
         2530  +    p->rc = SQLITE_NOMEM_BKPT;
  2531   2531     }
  2532   2532     if( p->aOnceFlag ) memset(p->aOnceFlag, 0, p->nOnceFlag);
  2533   2533     closeAllCursors(p);
  2534   2534     if( p->magic!=VDBE_MAGIC_RUN ){
  2535   2535       return SQLITE_OK;
  2536   2536     }
  2537   2537     checkActiveVdbeCnt(db);
................................................................................
  2684   2684       assert( db->nVdbeActive>=db->nVdbeRead );
  2685   2685       assert( db->nVdbeRead>=db->nVdbeWrite );
  2686   2686       assert( db->nVdbeWrite>=0 );
  2687   2687     }
  2688   2688     p->magic = VDBE_MAGIC_HALT;
  2689   2689     checkActiveVdbeCnt(db);
  2690   2690     if( db->mallocFailed ){
  2691         -    p->rc = SQLITE_NOMEM;
         2691  +    p->rc = SQLITE_NOMEM_BKPT;
  2692   2692     }
  2693   2693   
  2694   2694     /* If the auto-commit flag is set to true, then any locks that were held
  2695   2695     ** by connection db have now been released. Call sqlite3ConnectionUnlocked() 
  2696   2696     ** to invoke any required unlock-notify callbacks.
  2697   2697     */
  2698   2698     if( db->autoCommit ){
................................................................................
  3662   3662       sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
  3663   3663       sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
  3664   3664       v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
  3665   3665       n1 = v1==0 ? 0 : c1.n;
  3666   3666       v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
  3667   3667       n2 = v2==0 ? 0 : c2.n;
  3668   3668       rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
  3669         -    if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM;
         3669  +    if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM_BKPT;
  3670   3670       sqlite3VdbeMemRelease(&c1);
  3671   3671       sqlite3VdbeMemRelease(&c2);
  3672   3672       return rc;
  3673   3673     }
  3674   3674   }
  3675   3675   
  3676   3676   /*

Changes to src/vdbemem.c.

   134    134         if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
   135    135         pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
   136    136       }
   137    137       if( pMem->zMalloc==0 ){
   138    138         sqlite3VdbeMemSetNull(pMem);
   139    139         pMem->z = 0;
   140    140         pMem->szMalloc = 0;
   141         -      return SQLITE_NOMEM;
          141  +      return SQLITE_NOMEM_BKPT;
   142    142       }else{
   143    143         pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
   144    144       }
   145    145     }
   146    146   
   147    147     if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
   148    148       memcpy(pMem->zMalloc, pMem->z, pMem->n);
................................................................................
   192    192     int f;
   193    193     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
   194    194     assert( (pMem->flags&MEM_RowSet)==0 );
   195    195     ExpandBlob(pMem);
   196    196     f = pMem->flags;
   197    197     if( (f&(MEM_Str|MEM_Blob)) && (pMem->szMalloc==0 || pMem->z!=pMem->zMalloc) ){
   198    198       if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
   199         -      return SQLITE_NOMEM;
          199  +      return SQLITE_NOMEM_BKPT;
   200    200       }
   201    201       pMem->z[pMem->n] = 0;
   202    202       pMem->z[pMem->n+1] = 0;
   203    203       pMem->flags |= MEM_Term;
   204    204     }
   205    205     pMem->flags &= ~MEM_Ephem;
   206    206   #ifdef SQLITE_DEBUG
................................................................................
   224    224   
   225    225       /* Set nByte to the number of bytes required to store the expanded blob. */
   226    226       nByte = pMem->n + pMem->u.nZero;
   227    227       if( nByte<=0 ){
   228    228         nByte = 1;
   229    229       }
   230    230       if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
   231         -      return SQLITE_NOMEM;
          231  +      return SQLITE_NOMEM_BKPT;
   232    232       }
   233    233   
   234    234       memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
   235    235       pMem->n += pMem->u.nZero;
   236    236       pMem->flags &= ~(MEM_Zero|MEM_Term);
   237    237     }
   238    238     return SQLITE_OK;
................................................................................
   241    241   
   242    242   /*
   243    243   ** It is already known that pMem contains an unterminated string.
   244    244   ** Add the zero terminator.
   245    245   */
   246    246   static SQLITE_NOINLINE int vdbeMemAddTerminator(Mem *pMem){
   247    247     if( sqlite3VdbeMemGrow(pMem, pMem->n+2, 1) ){
   248         -    return SQLITE_NOMEM;
          248  +    return SQLITE_NOMEM_BKPT;
   249    249     }
   250    250     pMem->z[pMem->n] = 0;
   251    251     pMem->z[pMem->n+1] = 0;
   252    252     pMem->flags |= MEM_Term;
   253    253     return SQLITE_OK;
   254    254   }
   255    255   
................................................................................
   290    290     assert( !(fg&(MEM_Str|MEM_Blob)) );
   291    291     assert( fg&(MEM_Int|MEM_Real) );
   292    292     assert( (pMem->flags&MEM_RowSet)==0 );
   293    293     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
   294    294   
   295    295   
   296    296     if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){
   297         -    return SQLITE_NOMEM;
          297  +    return SQLITE_NOMEM_BKPT;
   298    298     }
   299    299   
   300    300     /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
   301    301     ** string representation of the value. Then, if the required encoding
   302    302     ** is UTF-16le or UTF-16be do a translation.
   303    303     ** 
   304    304     ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
................................................................................
   901    901       if( nByte>iLimit ){
   902    902         return SQLITE_TOOBIG;
   903    903       }
   904    904       testcase( nAlloc==0 );
   905    905       testcase( nAlloc==31 );
   906    906       testcase( nAlloc==32 );
   907    907       if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
   908         -      return SQLITE_NOMEM;
          908  +      return SQLITE_NOMEM_BKPT;
   909    909       }
   910    910       memcpy(pMem->z, z, nAlloc);
   911    911     }else if( xDel==SQLITE_DYNAMIC ){
   912    912       sqlite3VdbeMemRelease(pMem);
   913    913       pMem->zMalloc = pMem->z = (char *)z;
   914    914       pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
   915    915     }else{
................................................................................
   921    921   
   922    922     pMem->n = nByte;
   923    923     pMem->flags = flags;
   924    924     pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
   925    925   
   926    926   #ifndef SQLITE_OMIT_UTF16
   927    927     if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
   928         -    return SQLITE_NOMEM;
          928  +    return SQLITE_NOMEM_BKPT;
   929    929     }
   930    930   #endif
   931    931   
   932    932     if( nByte>iLimit ){
   933    933       return SQLITE_TOOBIG;
   934    934     }
   935    935   
................................................................................
  1202   1202     ){
  1203   1203       return SQLITE_OK;
  1204   1204     }
  1205   1205   
  1206   1206     if( pList ){
  1207   1207       apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
  1208   1208       if( apVal==0 ){
  1209         -      rc = SQLITE_NOMEM;
         1209  +      rc = SQLITE_NOMEM_BKPT;
  1210   1210         goto value_from_function_out;
  1211   1211       }
  1212   1212       for(i=0; i<nVal; i++){
  1213   1213         rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
  1214   1214         if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
  1215   1215       }
  1216   1216     }
  1217   1217   
  1218   1218     pVal = valueNew(db, pCtx);
  1219   1219     if( pVal==0 ){
  1220         -    rc = SQLITE_NOMEM;
         1220  +    rc = SQLITE_NOMEM_BKPT;
  1221   1221       goto value_from_function_out;
  1222   1222     }
  1223   1223   
  1224   1224     assert( pCtx->pParse->rc==SQLITE_OK );
  1225   1225     memset(&ctx, 0, sizeof(ctx));
  1226   1226     ctx.pOut = pVal;
  1227   1227     ctx.pFunc = pFunc;
................................................................................
  1386   1386     sqlite3DbFree(db, zVal);
  1387   1387     assert( *ppVal==0 );
  1388   1388   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1389   1389     if( pCtx==0 ) sqlite3ValueFree(pVal);
  1390   1390   #else
  1391   1391     assert( pCtx==0 ); sqlite3ValueFree(pVal);
  1392   1392   #endif
  1393         -  return SQLITE_NOMEM;
         1393  +  return SQLITE_NOMEM_BKPT;
  1394   1394   }
  1395   1395   
  1396   1396   /*
  1397   1397   ** Create a new sqlite3_value object, containing the value of pExpr.
  1398   1398   **
  1399   1399   ** This only works for very simple expressions that consist of one constant
  1400   1400   ** token (i.e. "5", "5.1", "'a string'"). If the expression can
................................................................................
  1640   1640       iField += szField;
  1641   1641     }
  1642   1642     testcase( iField==nRec );
  1643   1643     testcase( iField==nRec+1 );
  1644   1644     if( iField>nRec ) return SQLITE_CORRUPT_BKPT;
  1645   1645     if( pMem==0 ){
  1646   1646       pMem = *ppVal = sqlite3ValueNew(db);
  1647         -    if( pMem==0 ) return SQLITE_NOMEM;
         1647  +    if( pMem==0 ) return SQLITE_NOMEM_BKPT;
  1648   1648     }
  1649   1649     sqlite3VdbeSerialGet(&a[iField-szField], t, pMem);
  1650   1650     pMem->enc = ENC(db);
  1651   1651     return SQLITE_OK;
  1652   1652   }
  1653   1653   
  1654   1654   /*

Changes to src/vdbesort.c.

   536    536   
   537    537       /* Extend the p->aAlloc[] allocation if required. */
   538    538       if( p->nAlloc<nByte ){
   539    539         u8 *aNew;
   540    540         int nNew = MAX(128, p->nAlloc*2);
   541    541         while( nByte>nNew ) nNew = nNew*2;
   542    542         aNew = sqlite3Realloc(p->aAlloc, nNew);
   543         -      if( !aNew ) return SQLITE_NOMEM;
          543  +      if( !aNew ) return SQLITE_NOMEM_BKPT;
   544    544         p->nAlloc = nNew;
   545    545         p->aAlloc = aNew;
   546    546       }
   547    547   
   548    548       /* Copy as much data as is available in the buffer into the start of
   549    549       ** p->aAlloc[].  */
   550    550       memcpy(p->aAlloc, &p->aBuffer[iBuf], nAvail);
................................................................................
   648    648   
   649    649     rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
   650    650     if( rc==SQLITE_OK && pReadr->aMap==0 ){
   651    651       int pgsz = pTask->pSorter->pgsz;
   652    652       int iBuf = pReadr->iReadOff % pgsz;
   653    653       if( pReadr->aBuffer==0 ){
   654    654         pReadr->aBuffer = (u8*)sqlite3Malloc(pgsz);
   655         -      if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM;
          655  +      if( pReadr->aBuffer==0 ) rc = SQLITE_NOMEM_BKPT;
   656    656         pReadr->nBuffer = pgsz;
   657    657       }
   658    658       if( rc==SQLITE_OK && iBuf ){
   659    659         int nRead = pgsz - iBuf;
   660    660         if( (pReadr->iReadOff + nRead) > pReadr->iEof ){
   661    661           nRead = (int)(pReadr->iEof - pReadr->iReadOff);
   662    662         }
................................................................................
   964    964     assert( pCsr->eCurType==CURTYPE_SORTER );
   965    965     szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
   966    966     sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
   967    967   
   968    968     pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
   969    969     pCsr->uc.pSorter = pSorter;
   970    970     if( pSorter==0 ){
   971         -    rc = SQLITE_NOMEM;
          971  +    rc = SQLITE_NOMEM_BKPT;
   972    972     }else{
   973    973       pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
   974    974       memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
   975    975       pKeyInfo->db = 0;
   976    976       if( nField && nWorker==0 ){
   977    977         pKeyInfo->nXField += (pKeyInfo->nField - nField);
   978    978         pKeyInfo->nField = nField;
................................................................................
   998    998         ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
   999    999         ** large heap allocations.
  1000   1000         */
  1001   1001         if( sqlite3GlobalConfig.pScratch==0 ){
  1002   1002           assert( pSorter->iMemory==0 );
  1003   1003           pSorter->nMemory = pgsz;
  1004   1004           pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
  1005         -        if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM;
         1005  +        if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
  1006   1006         }
  1007   1007       }
  1008   1008   
  1009   1009       if( (pKeyInfo->nField+pKeyInfo->nXField)<13 
  1010   1010        && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
  1011   1011       ){
  1012   1012         pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
................................................................................
  1320   1320   static int vdbeSortAllocUnpacked(SortSubtask *pTask){
  1321   1321     if( pTask->pUnpacked==0 ){
  1322   1322       char *pFree;
  1323   1323       pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(
  1324   1324           pTask->pSorter->pKeyInfo, 0, 0, &pFree
  1325   1325       );
  1326   1326       assert( pTask->pUnpacked==(UnpackedRecord*)pFree );
  1327         -    if( pFree==0 ) return SQLITE_NOMEM;
         1327  +    if( pFree==0 ) return SQLITE_NOMEM_BKPT;
  1328   1328       pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
  1329   1329       pTask->pUnpacked->errCode = 0;
  1330   1330     }
  1331   1331     return SQLITE_OK;
  1332   1332   }
  1333   1333   
  1334   1334   
................................................................................
  1395   1395     if( rc!=SQLITE_OK ) return rc;
  1396   1396   
  1397   1397     p = pList->pList;
  1398   1398     pTask->xCompare = vdbeSorterGetCompare(pTask->pSorter);
  1399   1399   
  1400   1400     aSlot = (SorterRecord **)sqlite3MallocZero(64 * sizeof(SorterRecord *));
  1401   1401     if( !aSlot ){
  1402         -    return SQLITE_NOMEM;
         1402  +    return SQLITE_NOMEM_BKPT;
  1403   1403     }
  1404   1404   
  1405   1405     while( p ){
  1406   1406       SorterRecord *pNext;
  1407   1407       if( pList->aMemory ){
  1408   1408         if( (u8*)p==pList->aMemory ){
  1409   1409           pNext = 0;
................................................................................
  1445   1445     PmaWriter *p,                   /* Object to populate */
  1446   1446     int nBuf,                       /* Buffer size */
  1447   1447     i64 iStart                      /* Offset of pFd to begin writing at */
  1448   1448   ){
  1449   1449     memset(p, 0, sizeof(PmaWriter));
  1450   1450     p->aBuffer = (u8*)sqlite3Malloc(nBuf);
  1451   1451     if( !p->aBuffer ){
  1452         -    p->eFWErr = SQLITE_NOMEM;
         1452  +    p->eFWErr = SQLITE_NOMEM_BKPT;
  1453   1453     }else{
  1454   1454       p->iBufEnd = p->iBufStart = (iStart % nBuf);
  1455   1455       p->iWriteOff = iStart - p->iBufStart;
  1456   1456       p->nBuffer = nBuf;
  1457   1457       p->pFd = pFd;
  1458   1458     }
  1459   1459   }
................................................................................
  1733   1733         pSorter->list.pList = 0;
  1734   1734         pSorter->list.szPMA = 0;
  1735   1735         if( aMem ){
  1736   1736           pSorter->list.aMemory = aMem;
  1737   1737           pSorter->nMemory = sqlite3MallocSize(aMem);
  1738   1738         }else if( pSorter->list.aMemory ){
  1739   1739           pSorter->list.aMemory = sqlite3Malloc(pSorter->nMemory);
  1740         -        if( !pSorter->list.aMemory ) return SQLITE_NOMEM;
         1740  +        if( !pSorter->list.aMemory ) return SQLITE_NOMEM_BKPT;
  1741   1741         }
  1742   1742   
  1743   1743         rc = vdbeSorterCreateThread(pTask, vdbeSorterFlushThread, pCtx);
  1744   1744       }
  1745   1745     }
  1746   1746   
  1747   1747     return rc;
................................................................................
  1824   1824         int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
  1825   1825         int nNew = pSorter->nMemory * 2;
  1826   1826         while( nNew < nMin ) nNew = nNew*2;
  1827   1827         if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
  1828   1828         if( nNew < nMin ) nNew = nMin;
  1829   1829   
  1830   1830         aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
  1831         -      if( !aNew ) return SQLITE_NOMEM;
         1831  +      if( !aNew ) return SQLITE_NOMEM_BKPT;
  1832   1832         pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
  1833   1833         pSorter->list.aMemory = aNew;
  1834   1834         pSorter->nMemory = nNew;
  1835   1835       }
  1836   1836   
  1837   1837       pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
  1838   1838       pSorter->iMemory += ROUND8(nReq);
  1839   1839       if( pSorter->list.pList ){
  1840   1840         pNew->u.iNext = (int)((u8*)(pSorter->list.pList) - pSorter->list.aMemory);
  1841   1841       }
  1842   1842     }else{
  1843   1843       pNew = (SorterRecord *)sqlite3Malloc(nReq);
  1844   1844       if( pNew==0 ){
  1845         -      return SQLITE_NOMEM;
         1845  +      return SQLITE_NOMEM_BKPT;
  1846   1846       }
  1847   1847       pNew->u.pNext = pSorter->list.pList;
  1848   1848     }
  1849   1849   
  1850   1850     memcpy(SRVAL(pNew), pVal->z, pVal->n);
  1851   1851     pNew->nVal = pVal->n;
  1852   1852     pSorter->list.pList = pNew;
................................................................................
  1985   1985     if( pIncr ){
  1986   1986       pIncr->pMerger = pMerger;
  1987   1987       pIncr->pTask = pTask;
  1988   1988       pIncr->mxSz = MAX(pTask->pSorter->mxKeysize+9,pTask->pSorter->mxPmaSize/2);
  1989   1989       pTask->file2.iEof += pIncr->mxSz;
  1990   1990     }else{
  1991   1991       vdbeMergeEngineFree(pMerger);
  1992         -    rc = SQLITE_NOMEM;
         1992  +    rc = SQLITE_NOMEM_BKPT;
  1993   1993     }
  1994   1994     return rc;
  1995   1995   }
  1996   1996   
  1997   1997   #if SQLITE_MAX_WORKER_THREADS>0
  1998   1998   /*
  1999   1999   ** Set the "use-threads" flag on object pIncr.
................................................................................
  2290   2290   ){
  2291   2291     MergeEngine *pNew;              /* Merge engine to return */
  2292   2292     i64 iOff = *piOffset;
  2293   2293     int i;
  2294   2294     int rc = SQLITE_OK;
  2295   2295   
  2296   2296     *ppOut = pNew = vdbeMergeEngineNew(nPMA);
  2297         -  if( pNew==0 ) rc = SQLITE_NOMEM;
         2297  +  if( pNew==0 ) rc = SQLITE_NOMEM_BKPT;
  2298   2298   
  2299   2299     for(i=0; i<nPMA && rc==SQLITE_OK; i++){
  2300   2300       i64 nDummy;
  2301   2301       PmaReader *pReadr = &pNew->aReadr[i];
  2302   2302       rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr, &nDummy);
  2303   2303       iOff = pReadr->iEof;
  2304   2304     }
................................................................................
  2361   2361     for(i=1; i<nDepth && rc==SQLITE_OK; i++){
  2362   2362       int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT;
  2363   2363       PmaReader *pReadr = &p->aReadr[iIter];
  2364   2364   
  2365   2365       if( pReadr->pIncr==0 ){
  2366   2366         MergeEngine *pNew = vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
  2367   2367         if( pNew==0 ){
  2368         -        rc = SQLITE_NOMEM;
         2368  +        rc = SQLITE_NOMEM_BKPT;
  2369   2369         }else{
  2370   2370           rc = vdbeIncrMergerNew(pTask, pNew, &pReadr->pIncr);
  2371   2371         }
  2372   2372       }
  2373   2373       if( rc==SQLITE_OK ){
  2374   2374         p = pReadr->pIncr->pMerger;
  2375   2375         nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
................................................................................
  2406   2406   #if SQLITE_MAX_WORKER_THREADS>0
  2407   2407     /* If the sorter uses more than one task, then create the top-level 
  2408   2408     ** MergeEngine here. This MergeEngine will read data from exactly 
  2409   2409     ** one PmaReader per sub-task.  */
  2410   2410     assert( pSorter->bUseThreads || pSorter->nTask==1 );
  2411   2411     if( pSorter->nTask>1 ){
  2412   2412       pMain = vdbeMergeEngineNew(pSorter->nTask);
  2413         -    if( pMain==0 ) rc = SQLITE_NOMEM;
         2413  +    if( pMain==0 ) rc = SQLITE_NOMEM_BKPT;
  2414   2414     }
  2415   2415   #endif
  2416   2416   
  2417   2417     for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
  2418   2418       SortSubtask *pTask = &pSorter->aTask[iTask];
  2419   2419       assert( pTask->nPMA>0 || SQLITE_MAX_WORKER_THREADS>0 );
  2420   2420       if( SQLITE_MAX_WORKER_THREADS==0 || pTask->nPMA ){
................................................................................
  2424   2424   
  2425   2425         if( pTask->nPMA<=SORTER_MAX_MERGE_COUNT ){
  2426   2426           rc = vdbeMergeEngineLevel0(pTask, pTask->nPMA, &iReadOff, &pRoot);
  2427   2427         }else{
  2428   2428           int i;
  2429   2429           int iSeq = 0;
  2430   2430           pRoot = vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
  2431         -        if( pRoot==0 ) rc = SQLITE_NOMEM;
         2431  +        if( pRoot==0 ) rc = SQLITE_NOMEM_BKPT;
  2432   2432           for(i=0; i<pTask->nPMA && rc==SQLITE_OK; i += SORTER_MAX_MERGE_COUNT){
  2433   2433             MergeEngine *pMerger = 0; /* New level-0 PMA merger */
  2434   2434             int nReader;              /* Number of level-0 PMAs to merge */
  2435   2435   
  2436   2436             nReader = MIN(pTask->nPMA - i, SORTER_MAX_MERGE_COUNT);
  2437   2437             rc = vdbeMergeEngineLevel0(pTask, nReader, &iReadOff, &pMerger);
  2438   2438             if( rc==SQLITE_OK ){
................................................................................
  2495   2495         int iTask;
  2496   2496         PmaReader *pReadr = 0;
  2497   2497         SortSubtask *pLast = &pSorter->aTask[pSorter->nTask-1];
  2498   2498         rc = vdbeSortAllocUnpacked(pLast);
  2499   2499         if( rc==SQLITE_OK ){
  2500   2500           pReadr = (PmaReader*)sqlite3DbMallocZero(db, sizeof(PmaReader));
  2501   2501           pSorter->pReader = pReadr;
  2502         -        if( pReadr==0 ) rc = SQLITE_NOMEM;
         2502  +        if( pReadr==0 ) rc = SQLITE_NOMEM_BKPT;
  2503   2503         }
  2504   2504         if( rc==SQLITE_OK ){
  2505   2505           rc = vdbeIncrMergerNew(pLast, pMain, &pReadr->pIncr);
  2506   2506           if( rc==SQLITE_OK ){
  2507   2507             vdbeIncrMergerSetThreads(pReadr->pIncr);
  2508   2508             for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
  2509   2509               IncrMerger *pIncr;
................................................................................
  2672   2672     VdbeSorter *pSorter;
  2673   2673     void *pKey; int nKey;           /* Sorter key to copy into pOut */
  2674   2674   
  2675   2675     assert( pCsr->eCurType==CURTYPE_SORTER );
  2676   2676     pSorter = pCsr->uc.pSorter;
  2677   2677     pKey = vdbeSorterRowkey(pSorter, &nKey);
  2678   2678     if( sqlite3VdbeMemClearAndResize(pOut, nKey) ){
  2679         -    return SQLITE_NOMEM;
         2679  +    return SQLITE_NOMEM_BKPT;
  2680   2680     }
  2681   2681     pOut->n = nKey;
  2682   2682     MemSetTypeFlag(pOut, MEM_Blob);
  2683   2683     memcpy(pOut->z, pKey, nKey);
  2684   2684   
  2685   2685     return SQLITE_OK;
  2686   2686   }
................................................................................
  2717   2717     pSorter = pCsr->uc.pSorter;
  2718   2718     r2 = pSorter->pUnpacked;
  2719   2719     pKeyInfo = pCsr->pKeyInfo;
  2720   2720     if( r2==0 ){
  2721   2721       char *p;
  2722   2722       r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo,0,0,&p);
  2723   2723       assert( pSorter->pUnpacked==(UnpackedRecord*)p );
  2724         -    if( r2==0 ) return SQLITE_NOMEM;
         2724  +    if( r2==0 ) return SQLITE_NOMEM_BKPT;
  2725   2725       r2->nField = nKeyCol;
  2726   2726     }
  2727   2727     assert( r2->nField==nKeyCol );
  2728   2728   
  2729   2729     pKey = vdbeSorterRowkey(pSorter, &nKey);
  2730   2730     sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
  2731   2731     for(i=0; i<nKeyCol; i++){

Changes to src/vtab.c.

   502    502         );
   503    503         return SQLITE_LOCKED;
   504    504       }
   505    505     }
   506    506   
   507    507     zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
   508    508     if( !zModuleName ){
   509         -    return SQLITE_NOMEM;
          509  +    return SQLITE_NOMEM_BKPT;
   510    510     }
   511    511   
   512    512     pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
   513    513     if( !pVTable ){
   514    514       sqlite3DbFree(db, zModuleName);
   515         -    return SQLITE_NOMEM;
          515  +    return SQLITE_NOMEM_BKPT;
   516    516     }
   517    517     pVTable->db = db;
   518    518     pVTable->pMod = pMod;
   519    519   
   520    520     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   521    521     pTab->azModuleArg[1] = db->aDb[iDb].zName;
   522    522   
................................................................................
   651    651   
   652    652     /* Grow the sqlite3.aVTrans array if required */
   653    653     if( (db->nVTrans%ARRAY_INCR)==0 ){
   654    654       VTable **aVTrans;
   655    655       int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
   656    656       aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
   657    657       if( !aVTrans ){
   658         -      return SQLITE_NOMEM;
          658  +      return SQLITE_NOMEM_BKPT;
   659    659       }
   660    660       memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
   661    661       db->aVTrans = aVTrans;
   662    662     }
   663    663   
   664    664     return SQLITE_OK;
   665    665   }
................................................................................
   743    743       return SQLITE_MISUSE_BKPT;
   744    744     }
   745    745     pTab = pCtx->pTab;
   746    746     assert( (pTab->tabFlags & TF_Virtual)!=0 );
   747    747   
   748    748     pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
   749    749     if( pParse==0 ){
   750         -    rc = SQLITE_NOMEM;
          750  +    rc = SQLITE_NOMEM_BKPT;
   751    751     }else{
   752    752       pParse->declareVtab = 1;
   753    753       pParse->db = db;
   754    754       pParse->nQueryLoop = 1;
   755    755     
   756    756       if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr) 
   757    757        && pParse->pNewTable

Changes to src/wal.c.

   542    542     /* Enlarge the pWal->apWiData[] array if required */
   543    543     if( pWal->nWiData<=iPage ){
   544    544       int nByte = sizeof(u32*)*(iPage+1);
   545    545       volatile u32 **apNew;
   546    546       apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
   547    547       if( !apNew ){
   548    548         *ppPage = 0;
   549         -      return SQLITE_NOMEM;
          549  +      return SQLITE_NOMEM_BKPT;
   550    550       }
   551    551       memset((void*)&apNew[pWal->nWiData], 0,
   552    552              sizeof(u32*)*(iPage+1-pWal->nWiData));
   553    553       pWal->apWiData = apNew;
   554    554       pWal->nWiData = iPage+1;
   555    555     }
   556    556   
   557    557     /* Request a pointer to the required page from the VFS */
   558    558     if( pWal->apWiData[iPage]==0 ){
   559    559       if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){
   560    560         pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ);
   561         -      if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
          561  +      if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
   562    562       }else{
   563    563         rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, 
   564    564             pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
   565    565         );
   566    566         if( rc==SQLITE_READONLY ){
   567    567           pWal->readOnly |= WAL_SHM_RDONLY;
   568    568           rc = SQLITE_OK;
................................................................................
  1169   1169         goto finished;
  1170   1170       }
  1171   1171   
  1172   1172       /* Malloc a buffer to read frames into. */
  1173   1173       szFrame = szPage + WAL_FRAME_HDRSIZE;
  1174   1174       aFrame = (u8 *)sqlite3_malloc64(szFrame);
  1175   1175       if( !aFrame ){
  1176         -      rc = SQLITE_NOMEM;
         1176  +      rc = SQLITE_NOMEM_BKPT;
  1177   1177         goto recovery_error;
  1178   1178       }
  1179   1179       aData = &aFrame[WAL_FRAME_HDRSIZE];
  1180   1180   
  1181   1181       /* Read all frames from the log file. */
  1182   1182       iFrame = 0;
  1183   1183       for(iOffset=WAL_HDRSIZE; (iOffset+szFrame)<=nSize; iOffset+=szFrame){
................................................................................
  1307   1307   #endif
  1308   1308   
  1309   1309   
  1310   1310     /* Allocate an instance of struct Wal to return. */
  1311   1311     *ppWal = 0;
  1312   1312     pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
  1313   1313     if( !pRet ){
  1314         -    return SQLITE_NOMEM;
         1314  +    return SQLITE_NOMEM_BKPT;
  1315   1315     }
  1316   1316   
  1317   1317     pRet->pVfs = pVfs;
  1318   1318     pRet->pWalFd = (sqlite3_file *)&pRet[1];
  1319   1319     pRet->pDbFd = pDbFd;
  1320   1320     pRet->readLock = -1;
  1321   1321     pRet->mxWalSize = mxWalSize;
................................................................................
  1571   1571     /* Allocate space for the WalIterator object. */
  1572   1572     nSegment = walFramePage(iLast) + 1;
  1573   1573     nByte = sizeof(WalIterator) 
  1574   1574           + (nSegment-1)*sizeof(struct WalSegment)
  1575   1575           + iLast*sizeof(ht_slot);
  1576   1576     p = (WalIterator *)sqlite3_malloc64(nByte);
  1577   1577     if( !p ){
  1578         -    return SQLITE_NOMEM;
         1578  +    return SQLITE_NOMEM_BKPT;
  1579   1579     }
  1580   1580     memset(p, 0, nByte);
  1581   1581     p->nSegment = nSegment;
  1582   1582   
  1583   1583     /* Allocate temporary space used by the merge-sort routine. This block
  1584   1584     ** of memory will be freed before this function returns.
  1585   1585     */
  1586   1586     aTmp = (ht_slot *)sqlite3_malloc64(
  1587   1587         sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
  1588   1588     );
  1589   1589     if( !aTmp ){
  1590         -    rc = SQLITE_NOMEM;
         1590  +    rc = SQLITE_NOMEM_BKPT;
  1591   1591     }
  1592   1592   
  1593   1593     for(i=0; rc==SQLITE_OK && i<nSegment; i++){
  1594   1594       volatile ht_slot *aHash;
  1595   1595       u32 iZero;
  1596   1596       volatile u32 *aPgno;
  1597   1597   
................................................................................
  2876   2876     int nTruncate,              /* The commit flag.  Usually 0.  >0 for commit */
  2877   2877     sqlite3_int64 iOffset       /* Byte offset at which to write */
  2878   2878   ){
  2879   2879     int rc;                         /* Result code from subfunctions */
  2880   2880     void *pData;                    /* Data actually written */
  2881   2881     u8 aFrame[WAL_FRAME_HDRSIZE];   /* Buffer to assemble frame-header in */
  2882   2882   #if defined(SQLITE_HAS_CODEC)
  2883         -  if( (pData = sqlite3PagerCodec(pPage))==0 ) return SQLITE_NOMEM;
         2883  +  if( (pData = sqlite3PagerCodec(pPage))==0 ) return SQLITE_NOMEM_BKPT;
  2884   2884   #else
  2885   2885     pData = pPage->pData;
  2886   2886   #endif
  2887   2887     walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame);
  2888   2888     rc = walWriteToLog(p, aFrame, sizeof(aFrame), iOffset);
  2889   2889     if( rc ) return rc;
  2890   2890     /* Write the page data */
................................................................................
  2905   2905     int rc = SQLITE_OK;             /* Return code */
  2906   2906     u8 *aBuf;                       /* Buffer to load data from wal file into */
  2907   2907     u8 aFrame[WAL_FRAME_HDRSIZE];   /* Buffer to assemble frame-headers in */
  2908   2908     u32 iRead;                      /* Next frame to read from wal file */
  2909   2909     i64 iCksumOff;
  2910   2910   
  2911   2911     aBuf = sqlite3_malloc(szPage + WAL_FRAME_HDRSIZE);
  2912         -  if( aBuf==0 ) return SQLITE_NOMEM;
         2912  +  if( aBuf==0 ) return SQLITE_NOMEM_BKPT;
  2913   2913   
  2914   2914     /* Find the checksum values to use as input for the recalculating the
  2915   2915     ** first checksum. If the first frame is frame 1 (implying that the current
  2916   2916     ** transaction restarted the wal file), these values must be read from the
  2917   2917     ** wal-file header. Otherwise, read them from the frame header of the
  2918   2918     ** previous frame.  */
  2919   2919     assert( pWal->iReCksum>0 );
................................................................................
  3375   3375     int rc = SQLITE_OK;
  3376   3376     WalIndexHdr *pRet;
  3377   3377   
  3378   3378     assert( pWal->readLock>=0 && pWal->writeLock==0 );
  3379   3379   
  3380   3380     pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr));
  3381   3381     if( pRet==0 ){
  3382         -    rc = SQLITE_NOMEM;
         3382  +    rc = SQLITE_NOMEM_BKPT;
  3383   3383     }else{
  3384   3384       memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr));
  3385   3385       *ppSnapshot = (sqlite3_snapshot*)pRet;
  3386   3386     }
  3387   3387   
  3388   3388     return rc;
  3389   3389   }

Changes to src/where.c.

  1732   1732   ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
  1733   1733   */
  1734   1734   static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
  1735   1735     WhereTerm **paNew;
  1736   1736     if( p->nLSlot>=n ) return SQLITE_OK;
  1737   1737     n = (n+7)&~7;
  1738   1738     paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
  1739         -  if( paNew==0 ) return SQLITE_NOMEM;
         1739  +  if( paNew==0 ) return SQLITE_NOMEM_BKPT;
  1740   1740     memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
  1741   1741     if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
  1742   1742     p->aLTerm = paNew;
  1743   1743     p->nLSlot = n;
  1744   1744     return SQLITE_OK;
  1745   1745   }
  1746   1746   
................................................................................
  1747   1747   /*
  1748   1748   ** Transfer content from the second pLoop into the first.
  1749   1749   */
  1750   1750   static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
  1751   1751     whereLoopClearUnion(db, pTo);
  1752   1752     if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
  1753   1753       memset(&pTo->u, 0, sizeof(pTo->u));
  1754         -    return SQLITE_NOMEM;
         1754  +    return SQLITE_NOMEM_BKPT;
  1755   1755     }
  1756   1756     memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
  1757   1757     memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
  1758   1758     if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
  1759   1759       pFrom->u.vtab.needFree = 0;
  1760   1760     }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
  1761   1761       pFrom->u.btree.pIndex = 0;
................................................................................
  2029   2029       sqlite3DebugPrintf("    add: ");
  2030   2030       whereLoopPrint(pTemplate, pBuilder->pWC);
  2031   2031     }
  2032   2032   #endif
  2033   2033     if( p==0 ){
  2034   2034       /* Allocate a new WhereLoop to add to the end of the list */
  2035   2035       *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
  2036         -    if( p==0 ) return SQLITE_NOMEM;
         2036  +    if( p==0 ) return SQLITE_NOMEM_BKPT;
  2037   2037       whereLoopInit(p);
  2038   2038       p->pNextLoop = 0;
  2039   2039     }else{
  2040   2040       /* We will be overwriting WhereLoop p[].  But before we do, first
  2041   2041       ** go through the rest of the list and delete any other entries besides
  2042   2042       ** p[] that are also supplated by pTemplate */
  2043   2043       WhereLoop **ppTail = &p->pNextLoop;
................................................................................
  2185   2185     LogEst saved_nOut;              /* Original value of pNew->nOut */
  2186   2186     int rc = SQLITE_OK;             /* Return code */
  2187   2187     LogEst rSize;                   /* Number of rows in the table */
  2188   2188     LogEst rLogSize;                /* Logarithm of table size */
  2189   2189     WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
  2190   2190   
  2191   2191     pNew = pBuilder->pNew;
  2192         -  if( db->mallocFailed ) return SQLITE_NOMEM;
         2192  +  if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
  2193   2193   
  2194   2194     assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
  2195   2195     assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
  2196   2196     if( pNew->wsFlags & WHERE_BTM_LIMIT ){
  2197   2197       opMask = WO_LT|WO_LE;
  2198   2198     }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){
  2199   2199       opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
................................................................................
  2802   2802     db = pParse->db;
  2803   2803     pWC = pBuilder->pWC;
  2804   2804     pNew = pBuilder->pNew;
  2805   2805     pSrc = &pWInfo->pTabList->a[pNew->iTab];
  2806   2806     pTab = pSrc->pTab;
  2807   2807     assert( IsVirtual(pTab) );
  2808   2808     pIdxInfo = allocateIndexInfo(pParse, pWC, mUnusable, pSrc,pBuilder->pOrderBy);
  2809         -  if( pIdxInfo==0 ) return SQLITE_NOMEM;
         2809  +  if( pIdxInfo==0 ) return SQLITE_NOMEM_BKPT;
  2810   2810     pNew->prereq = 0;
  2811   2811     pNew->rSetup = 0;
  2812   2812     pNew->wsFlags = WHERE_VIRTUALTABLE;
  2813   2813     pNew->nLTerm = 0;
  2814   2814     pNew->u.vtab.needFree = 0;
  2815   2815     pUsage = pIdxInfo->aConstraintUsage;
  2816   2816     nConstraint = pIdxInfo->nConstraint;
  2817   2817     if( whereLoopResize(db, pNew, nConstraint) ){
  2818   2818       sqlite3DbFree(db, pIdxInfo);
  2819         -    return SQLITE_NOMEM;
         2819  +    return SQLITE_NOMEM_BKPT;
  2820   2820     }
  2821   2821   
  2822   2822     for(iPhase=0; iPhase<=3; iPhase++){
  2823   2823       if( !seenIn && (iPhase&1)!=0 ){
  2824   2824         iPhase++;
  2825   2825         if( iPhase>3 ) break;
  2826   2826       }
................................................................................
  3517   3517       nOrderBy = pWInfo->pOrderBy->nExpr;
  3518   3518     }
  3519   3519   
  3520   3520     /* Allocate and initialize space for aTo, aFrom and aSortCost[] */
  3521   3521     nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
  3522   3522     nSpace += sizeof(LogEst) * nOrderBy;
  3523   3523     pSpace = sqlite3DbMallocRawNN(db, nSpace);
  3524         -  if( pSpace==0 ) return SQLITE_NOMEM;
         3524  +  if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
  3525   3525     aTo = (WherePath*)pSpace;
  3526   3526     aFrom = aTo+mxChoice;
  3527   3527     memset(aFrom, 0, sizeof(aFrom[0]));
  3528   3528     pX = (WhereLoop**)(aFrom+mxChoice);
  3529   3529     for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
  3530   3530       pFrom->aLoop = pX;
  3531   3531     }