/ Check-in [e00ed717]
Login

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

Overview
Comment:Merge latest trunk changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: e00ed717fbe456010ec6c746490d7c3e9d94ec5a
User & Date: dan 2014-03-03 14:45:06
Context
2014-03-03
15:13
Fix a harmless compiler warning. check-in: d7f6837e user: drh tags: experimental
14:45
Merge latest trunk changes. check-in: e00ed717 user: dan tags: experimental
14:20
Fix a segfault that can occur following an OOM error. check-in: 7fdd378d user: dan tags: trunk
2014-03-01
19:45
Merge trunk changes. check-in: 9c1747b5 user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/utf.c.

   313    313     }
   314    314     *z = 0;
   315    315     assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
   316    316   
   317    317     sqlite3VdbeMemRelease(pMem);
   318    318     pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
   319    319     pMem->enc = desiredEnc;
   320         -  pMem->flags |= (MEM_Term|MEM_Dyn);
          320  +  pMem->flags |= (MEM_Term);
   321    321     pMem->z = (char*)zOut;
   322    322     pMem->zMalloc = pMem->z;
   323    323   
   324    324   translate_out:
   325    325   #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
   326    326     {
   327    327       char zBuf[100];
................................................................................
   441    441     sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
   442    442     if( db->mallocFailed ){
   443    443       sqlite3VdbeMemRelease(&m);
   444    444       m.z = 0;
   445    445     }
   446    446     assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
   447    447     assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
   448         -  assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
   449    448     assert( m.z || db->mallocFailed );
   450    449     return m.z;
   451    450   }
   452    451   
   453    452   /*
   454    453   ** zIn is a UTF-16 encoded unicode string at least nChar characters long.
   455    454   ** Return the number of bytes in the first nChar unicode characters

Changes to src/vdbe.c.

   148    148   ** a pointer to a dynamically allocated string where some other entity
   149    149   ** is responsible for deallocating that string.  Because the register
   150    150   ** does not control the string, it might be deleted without the register
   151    151   ** knowing it.
   152    152   **
   153    153   ** This routine converts an ephemeral string into a dynamically allocated
   154    154   ** string that the register itself controls.  In other words, it
   155         -** converts an MEM_Ephem string into an MEM_Dyn string.
          155  +** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
   156    156   */
   157    157   #define Deephemeralize(P) \
   158    158      if( ((P)->flags&MEM_Ephem)!=0 \
   159    159          && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
   160    160   
   161    161   /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
   162    162   #define isSorter(x) ((x)->pSorter!=0)
................................................................................
   596    596   
   597    597       /* Sanity checking on other operands */
   598    598   #ifdef SQLITE_DEBUG
   599    599       if( (pOp->opflags & OPFLG_IN1)!=0 ){
   600    600         assert( pOp->p1>0 );
   601    601         assert( pOp->p1<=(p->nMem-p->nCursor) );
   602    602         assert( memIsValid(&aMem[pOp->p1]) );
          603  +      assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
   603    604         REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
   604    605       }
   605    606       if( (pOp->opflags & OPFLG_IN2)!=0 ){
   606    607         assert( pOp->p2>0 );
   607    608         assert( pOp->p2<=(p->nMem-p->nCursor) );
   608    609         assert( memIsValid(&aMem[pOp->p2]) );
          610  +      assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
   609    611         REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
   610    612       }
   611    613       if( (pOp->opflags & OPFLG_IN3)!=0 ){
   612    614         assert( pOp->p3>0 );
   613    615         assert( pOp->p3<=(p->nMem-p->nCursor) );
   614    616         assert( memIsValid(&aMem[pOp->p3]) );
          617  +      assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
   615    618         REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
   616    619       }
   617    620       if( (pOp->opflags & OPFLG_OUT2)!=0 ){
   618    621         assert( pOp->p2>0 );
   619    622         assert( pOp->p2<=(p->nMem-p->nCursor) );
   620    623         memAboutToChange(p, &aMem[pOp->p2]);
   621    624       }
................................................................................
   709    712   **
   710    713   ** Write the current address onto register P1
   711    714   ** and then jump to address P2.
   712    715   */
   713    716   case OP_Gosub: {            /* jump */
   714    717     assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
   715    718     pIn1 = &aMem[pOp->p1];
   716         -  assert( (pIn1->flags & MEM_Dyn)==0 );
          719  +  assert( VdbeMemDynamic(pIn1)==0 );
   717    720     memAboutToChange(p, pIn1);
   718    721     pIn1->flags = MEM_Int;
   719    722     pIn1->u.i = pc;
   720    723     REGISTER_TRACE(pOp->p1, pIn1);
   721    724     pc = pOp->p2 - 1;
   722    725     break;
   723    726   }
................................................................................
   782    785   ** If the co-routine ends with OP_Yield or OP_Return then continue
   783    786   ** to the next instruction.  But if the co-routine ends with
   784    787   ** OP_EndCoroutine, jump immediately to P2.
   785    788   */
   786    789   case OP_Yield: {            /* in1, jump */
   787    790     int pcDest;
   788    791     pIn1 = &aMem[pOp->p1];
   789         -  assert( (pIn1->flags & MEM_Dyn)==0 );
          792  +  assert( VdbeMemDynamic(pIn1)==0 );
   790    793     pIn1->flags = MEM_Int;
   791    794     pcDest = (int)pIn1->u.i;
   792    795     pIn1->u.i = pc;
   793    796     REGISTER_TRACE(pOp->p1, pIn1);
   794    797     pc = pcDest;
   795    798     break;
   796    799   }
................................................................................
   955    958   
   956    959   #ifndef SQLITE_OMIT_UTF16
   957    960     if( encoding!=SQLITE_UTF8 ){
   958    961       rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
   959    962       if( rc==SQLITE_TOOBIG ) goto too_big;
   960    963       if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
   961    964       assert( pOut->zMalloc==pOut->z );
   962         -    assert( pOut->flags & MEM_Dyn );
          965  +    assert( VdbeMemDynamic(pOut)==0 );
   963    966       pOut->zMalloc = 0;
   964    967       pOut->flags |= MEM_Static;
   965         -    pOut->flags &= ~MEM_Dyn;
   966    968       if( pOp->p4type==P4_DYNAMIC ){
   967    969         sqlite3DbFree(db, pOp->p4.z);
   968    970       }
   969    971       pOp->p4type = P4_DYNAMIC;
   970    972       pOp->p4.z = pOut->z;
   971    973       pOp->p1 = pOut->n;
   972    974     }
................................................................................
  1094   1096     pIn1 = &aMem[p1];
  1095   1097     pOut = &aMem[p2];
  1096   1098     do{
  1097   1099       assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
  1098   1100       assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
  1099   1101       assert( memIsValid(pIn1) );
  1100   1102       memAboutToChange(p, pOut);
         1103  +    VdbeMemRelease(pOut);
  1101   1104       zMalloc = pOut->zMalloc;
  1102         -    pOut->zMalloc = 0;
  1103         -    sqlite3VdbeMemMove(pOut, pIn1);
         1105  +    memcpy(pOut, pIn1, sizeof(Mem));
  1104   1106   #ifdef SQLITE_DEBUG
  1105   1107       if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
  1106   1108         pOut->pScopyFrom += p1 - pOp->p2;
  1107   1109       }
  1108   1110   #endif
         1111  +    pIn1->flags = MEM_Undefined;
         1112  +    pIn1->xDel = 0;
  1109   1113       pIn1->zMalloc = zMalloc;
  1110   1114       REGISTER_TRACE(p2++, pOut);
  1111   1115       pIn1++;
  1112   1116       pOut++;
  1113   1117     }while( n-- );
  1114   1118     break;
  1115   1119   }
................................................................................
  1278   1282     if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
  1279   1283     Stringify(pIn1, encoding);
  1280   1284     Stringify(pIn2, encoding);
  1281   1285     nByte = pIn1->n + pIn2->n;
  1282   1286     if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
  1283   1287       goto too_big;
  1284   1288     }
  1285         -  MemSetTypeFlag(pOut, MEM_Str);
  1286   1289     if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
  1287   1290       goto no_mem;
  1288   1291     }
         1292  +  MemSetTypeFlag(pOut, MEM_Str);
  1289   1293     if( pOut!=pIn2 ){
  1290   1294       memcpy(pOut->z, pIn2->z, pIn2->n);
  1291   1295     }
  1292   1296     memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
  1293   1297     pOut->z[nByte]=0;
  1294   1298     pOut->z[nByte+1] = 0;
  1295   1299     pOut->flags |= MEM_Term;
................................................................................
  2456   2460   
  2457   2461     /* Extract the content for the p2+1-th column.  Control can only
  2458   2462     ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
  2459   2463     ** all valid.
  2460   2464     */
  2461   2465     assert( p2<pC->nHdrParsed );
  2462   2466     assert( rc==SQLITE_OK );
         2467  +  assert( sqlite3VdbeCheckMemInvariants(pDest) );
  2463   2468     if( pC->szRow>=aOffset[p2+1] ){
  2464   2469       /* This is the common case where the desired content fits on the original
  2465   2470       ** page - where the content is not on an overflow page */
  2466   2471       VdbeMemRelease(pDest);
  2467   2472       sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
  2468   2473     }else{
  2469   2474       /* This branch happens only when content is on overflow pages */
................................................................................
  2493   2498       sqlite3VdbeSerialGet(zData, t, pDest);
  2494   2499       /* If we dynamically allocated space to hold the data (in the
  2495   2500       ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
  2496   2501       ** dynamically allocated space over to the pDest structure.
  2497   2502       ** This prevents a memory copy. */
  2498   2503       if( sMem.zMalloc ){
  2499   2504         assert( sMem.z==sMem.zMalloc );
  2500         -      assert( !(pDest->flags & MEM_Dyn) );
  2501         -      assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
         2505  +      assert( VdbeMemDynamic(pDest)==0 );
         2506  +      assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
  2502   2507         pDest->flags &= ~(MEM_Ephem|MEM_Static);
  2503   2508         pDest->flags |= MEM_Term;
  2504   2509         pDest->z = sMem.z;
  2505   2510         pDest->zMalloc = sMem.zMalloc;
  2506   2511       }
  2507   2512     }
  2508   2513     pDest->enc = encoding;
................................................................................
  2677   2682       j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
  2678   2683     }while( (++pRec)<=pLast );
  2679   2684     assert( i==nHdr );
  2680   2685     assert( j==nByte );
  2681   2686   
  2682   2687     assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
  2683   2688     pOut->n = (int)nByte;
  2684         -  pOut->flags = MEM_Blob | MEM_Dyn;
         2689  +  pOut->flags = MEM_Blob;
  2685   2690     pOut->xDel = 0;
  2686   2691     if( nZero ){
  2687   2692       pOut->u.nZero = nZero;
  2688   2693       pOut->flags |= MEM_Zero;
  2689   2694     }
  2690   2695     pOut->enc = SQLITE_UTF8;  /* In case the blob is ever converted to text */
  2691   2696     REGISTER_TRACE(pOp->p3, pOut);

Changes to src/vdbeInt.h.

   204    204   
   205    205   /* Whenever Mem contains a valid string or blob representation, one of
   206    206   ** the following flags must be set to determine the memory management
   207    207   ** policy for Mem.z.  The MEM_Term flag tells us whether or not the
   208    208   ** string is \000 or \u0000 terminated
   209    209   */
   210    210   #define MEM_Term      0x0200   /* String rep is nul terminated */
   211         -#define MEM_Dyn       0x0400   /* Need to call sqliteFree() on Mem.z */
          211  +#define MEM_Dyn       0x0400   /* Need to call Mem.xDel() on Mem.z */
   212    212   #define MEM_Static    0x0800   /* Mem.z points to a static string */
   213    213   #define MEM_Ephem     0x1000   /* Mem.z points to an ephemeral string */
   214    214   #define MEM_Agg       0x2000   /* Mem.z points to an agg function context */
   215    215   #define MEM_Zero      0x4000   /* Mem.i contains count of 0s appended to blob */
   216    216   #ifdef SQLITE_OMIT_INCRBLOB
   217    217     #undef MEM_Zero
   218    218     #define MEM_Zero 0x0000
................................................................................
   452    452   #else
   453    453   # define sqlite3VdbeEnter(X)
   454    454   # define sqlite3VdbeLeave(X)
   455    455   #endif
   456    456   
   457    457   #ifdef SQLITE_DEBUG
   458    458   void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
          459  +int sqlite3VdbeCheckMemInvariants(Mem*);
   459    460   #endif
   460    461   
   461    462   #ifndef SQLITE_OMIT_FOREIGN_KEY
   462    463   int sqlite3VdbeCheckFk(Vdbe *, int);
   463    464   #else
   464    465   # define sqlite3VdbeCheckFk(p,i) 0
   465    466   #endif

Changes to src/vdbeaux.c.

  1216   1216         for(pEnd=&p[N]; p<pEnd; p++){
  1217   1217           sqlite3DbFree(db, p->zMalloc);
  1218   1218         }
  1219   1219         return;
  1220   1220       }
  1221   1221       for(pEnd=&p[N]; p<pEnd; p++){
  1222   1222         assert( (&p[1])==pEnd || p[0].db==p[1].db );
         1223  +      assert( sqlite3VdbeCheckMemInvariants(p) );
  1223   1224   
  1224   1225         /* This block is really an inlined version of sqlite3VdbeMemRelease()
  1225   1226         ** that takes advantage of the fact that the memory cell value is 
  1226   1227         ** being set to NULL after releasing any dynamic resources.
  1227   1228         **
  1228   1229         ** The justification for duplicating code is that according to 
  1229   1230         ** callgrind, this causes a certain test case to hit the CPU 4.7 
................................................................................
  1409   1410       pMem->memType = MEM_Int;
  1410   1411       pMem++;
  1411   1412   
  1412   1413       if( sqlite3VdbeMemGrow(pMem, 32, 0) ){            /* P4 */
  1413   1414         assert( p->db->mallocFailed );
  1414   1415         return SQLITE_ERROR;
  1415   1416       }
  1416         -    pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
         1417  +    pMem->flags = MEM_Str|MEM_Term;
  1417   1418       zP4 = displayP4(pOp, pMem->z, 32);
  1418   1419       if( zP4!=pMem->z ){
  1419   1420         sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
  1420   1421       }else{
  1421   1422         assert( pMem->z!=0 );
  1422   1423         pMem->n = sqlite3Strlen30(pMem->z);
  1423   1424         pMem->enc = SQLITE_UTF8;
................................................................................
  1426   1427       pMem++;
  1427   1428   
  1428   1429       if( p->explain==1 ){
  1429   1430         if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
  1430   1431           assert( p->db->mallocFailed );
  1431   1432           return SQLITE_ERROR;
  1432   1433         }
  1433         -      pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
         1434  +      pMem->flags = MEM_Str|MEM_Term;
  1434   1435         pMem->n = 2;
  1435   1436         sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5);   /* P5 */
  1436   1437         pMem->memType = MEM_Str;
  1437   1438         pMem->enc = SQLITE_UTF8;
  1438   1439         pMem++;
  1439   1440     
  1440   1441   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  1441   1442         if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
  1442   1443           assert( p->db->mallocFailed );
  1443   1444           return SQLITE_ERROR;
  1444   1445         }
  1445         -      pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
         1446  +      pMem->flags = MEM_Str|MEM_Term;
  1446   1447         pMem->n = displayComment(pOp, zP4, pMem->z, 500);
  1447   1448         pMem->memType = MEM_Str;
  1448   1449         pMem->enc = SQLITE_UTF8;
  1449   1450   #else
  1450   1451         pMem->flags = MEM_Null;                       /* Comment */
  1451   1452         pMem->memType = MEM_Null;
  1452   1453   #endif

Changes to src/vdbemem.c.

    13     13   ** This file contains code use to manipulate "Mem" structure.  A "Mem"
    14     14   ** stores a single value in the VDBE.  Mem is an opaque structure visible
    15     15   ** only within the VDBE.  Interface routines refer to a Mem using the
    16     16   ** name sqlite_value
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "vdbeInt.h"
           20  +
           21  +#ifdef SQLITE_DEBUG
           22  +/*
           23  +** Check invariants on a Mem object.
           24  +**
           25  +** This routine is intended for use inside of assert() statements, like
           26  +** this:    assert( sqlite3VdbeCheckMemInvariants(pMem) );
           27  +*/
           28  +int sqlite3VdbeCheckMemInvariants(Mem *p){
           29  +  /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
           30  +  ** function for Mem.z 
           31  +  */
           32  +  assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
           33  +  assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
           34  +
           35  +  /* If p holds a string or blob, the Mem.z must point to exactly
           36  +  ** one of the following:
           37  +  **
           38  +  **   (1) Memory in Mem.zMalloc and managed by the Mem object
           39  +  **   (2) Memory to be freed using Mem.xDel
           40  +  **   (3) An ephermal string or blob
           41  +  **   (4) A static string or blob
           42  +  */
           43  +  if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
           44  +    assert( 
           45  +      ((p->z==p->zMalloc)? 1 : 0) +
           46  +      ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
           47  +      ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
           48  +      ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
           49  +    );
           50  +  }
           51  +
           52  +  return 1;
           53  +}
           54  +#endif
           55  +
    20     56   
    21     57   /*
    22     58   ** If pMem is an object with a valid string representation, this routine
    23     59   ** ensures the internal encoding for the string representation is
    24     60   ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
    25     61   **
    26     62   ** If pMem is not a string object, or the encoding of the string
................................................................................
    63     99   **
    64    100   ** If the bPreserve argument is true, then copy of the content of
    65    101   ** pMem->z into the new allocation.  pMem must be either a string or
    66    102   ** blob if bPreserve is true.  If bPreserve is false, any prior content
    67    103   ** in pMem->z is discarded.
    68    104   */
    69    105   int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
    70         -  assert( 1 >=
    71         -    ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
    72         -    (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + 
    73         -    ((pMem->flags&MEM_Ephem) ? 1 : 0) + 
    74         -    ((pMem->flags&MEM_Static) ? 1 : 0)
    75         -  );
          106  +  assert( sqlite3VdbeCheckMemInvariants(pMem) );
    76    107     assert( (pMem->flags&MEM_RowSet)==0 );
    77    108   
    78    109     /* If the bPreserve flag is set to true, then the memory cell must already
    79    110     ** contain a valid string or blob value.  */
    80    111     assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
    81    112     testcase( bPreserve && pMem->z==0 );
    82    113   
................................................................................
    86    117         pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
    87    118         bPreserve = 0;
    88    119       }else{
    89    120         sqlite3DbFree(pMem->db, pMem->zMalloc);
    90    121         pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
    91    122       }
    92    123       if( pMem->zMalloc==0 ){
    93         -      sqlite3VdbeMemRelease(pMem);
          124  +      VdbeMemRelease(pMem);
    94    125         pMem->flags = MEM_Null;  
    95    126         return SQLITE_NOMEM;
    96    127       }
    97    128     }
    98    129   
    99    130     if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
   100    131       memcpy(pMem->zMalloc, pMem->z, pMem->n);
   101    132     }
   102         -  if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
   103         -    assert( pMem->xDel!=SQLITE_DYNAMIC );
          133  +  if( (pMem->flags&MEM_Dyn)!=0 ){
          134  +    assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
   104    135       pMem->xDel((void *)(pMem->z));
   105    136     }
   106    137   
   107    138     pMem->z = pMem->zMalloc;
   108         -  pMem->flags &= ~(MEM_Ephem|MEM_Static);
          139  +  pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
   109    140     pMem->xDel = 0;
   110    141     return SQLITE_OK;
   111    142   }
   112    143   
   113    144   /*
   114    145   ** Make the given Mem object MEM_Dyn.  In other words, make it so
   115    146   ** that any TEXT or BLOB content is stored in memory obtained from
................................................................................
   270    301   */
   271    302   void sqlite3VdbeMemReleaseExternal(Mem *p){
   272    303     assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
   273    304     if( p->flags&MEM_Agg ){
   274    305       sqlite3VdbeMemFinalize(p, p->u.pDef);
   275    306       assert( (p->flags & MEM_Agg)==0 );
   276    307       sqlite3VdbeMemRelease(p);
   277         -  }else if( p->flags&MEM_Dyn && p->xDel ){
          308  +  }else if( p->flags&MEM_Dyn ){
   278    309       assert( (p->flags&MEM_RowSet)==0 );
   279         -    assert( p->xDel!=SQLITE_DYNAMIC );
          310  +    assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
   280    311       p->xDel((void *)p->z);
   281    312       p->xDel = 0;
   282    313     }else if( p->flags&MEM_RowSet ){
   283    314       sqlite3RowSetClear(p->u.pRowSet);
   284    315     }else if( p->flags&MEM_Frame ){
   285    316       sqlite3VdbeMemSetNull(p);
   286    317     }
................................................................................
   288    319   
   289    320   /*
   290    321   ** Release any memory held by the Mem. This may leave the Mem in an
   291    322   ** inconsistent state, for example with (Mem.z==0) and
   292    323   ** (Mem.memType==MEM_Str).
   293    324   */
   294    325   void sqlite3VdbeMemRelease(Mem *p){
          326  +  assert( sqlite3VdbeCheckMemInvariants(p) );
   295    327     VdbeMemRelease(p);
   296    328     if( p->zMalloc ){
   297    329       sqlite3DbFree(p->db, p->zMalloc);
   298    330       p->zMalloc = 0;
   299    331     }
   300    332     p->z = 0;
   301    333     assert( p->xDel==0 );  /* Zeroed by VdbeMemRelease() above */
................................................................................
   625    657   int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
   626    658     int rc = SQLITE_OK;
   627    659   
   628    660     assert( (pFrom->flags & MEM_RowSet)==0 );
   629    661     VdbeMemRelease(pTo);
   630    662     memcpy(pTo, pFrom, MEMCELLSIZE);
   631    663     pTo->flags &= ~MEM_Dyn;
          664  +  pTo->xDel = 0;
   632    665   
   633    666     if( pTo->flags&(MEM_Str|MEM_Blob) ){
   634    667       if( 0==(pFrom->flags&MEM_Static) ){
   635    668         pTo->flags |= MEM_Ephem;
   636    669         rc = sqlite3VdbeMemMakeWriteable(pTo);
   637    670       }
   638    671     }
................................................................................
   791    824     assert( zData!=0 );
   792    825   
   793    826     if( offset+amt<=available ){
   794    827       sqlite3VdbeMemRelease(pMem);
   795    828       pMem->z = &zData[offset];
   796    829       pMem->flags = MEM_Blob|MEM_Ephem;
   797    830     }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
   798         -    pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
          831  +    pMem->flags = MEM_Blob|MEM_Term;
   799    832       pMem->enc = 0;
   800    833       pMem->memType = MEM_Blob;
   801    834       if( key ){
   802    835         rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
   803    836       }else{
   804    837         rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
   805    838       }

Changes to src/where.c.

  5866   5866       assert( pTab!=0 );
  5867   5867       pLoop = pLevel->pWLoop;
  5868   5868   
  5869   5869       /* For a co-routine, change all OP_Column references to the table of
  5870   5870       ** the co-routine into OP_SCopy of result contained in a register.
  5871   5871       ** OP_Rowid becomes OP_Null.
  5872   5872       */
  5873         -    if( pTabItem->viaCoroutine ){
         5873  +    if( pTabItem->viaCoroutine && !db->mallocFailed ){
  5874   5874         last = sqlite3VdbeCurrentAddr(v);
  5875   5875         k = pLevel->addrBody;
  5876   5876         pOp = sqlite3VdbeGetOp(v, k);
  5877   5877         for(; k<last; k++, pOp++){
  5878   5878           if( pOp->p1!=pLevel->iTabCur ) continue;
  5879   5879           if( pOp->opcode==OP_Column ){
  5880   5880             pOp->opcode = OP_SCopy;