Index: src/alter.c ================================================================== --- src/alter.c +++ src/alter.c @@ -811,20 +811,21 @@ ** fails if the Select objects on it have already been expanded and ** resolved. */ pCopy = sqlite3WithDup(pParse->db, pWith); sqlite3WithPush(pParse, pCopy, 1); } - for(i=0; inCte; i++){ - Select *p = pWith->a[i].pSelect; - NameContext sNC; - memset(&sNC, 0, sizeof(sNC)); - sNC.pParse = pParse; - if( pCopy ) sqlite3SelectPrep(sNC.pParse, p, &sNC); - sqlite3WalkSelect(pWalker, p); - sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols); - } - if( pCopy && pParse->pWith==pCopy ){ + if( pParse->db->mallocFailed==0 ){ + assert( pCopy ); + for(i=0; inCte; i++){ + Select *p = pWith->a[i].pSelect; + NameContext sNC; + memset(&sNC, 0, sizeof(sNC)); + sNC.pParse = pParse; + sqlite3SelectPrep(sNC.pParse, p, &sNC); + sqlite3WalkSelect(pWalker, p); + sqlite3RenameExprlistUnmap(pParse, pWith->a[i].pCols); + } pParse->pWith = pCopy->pOuter; } } }