/ Check-in [80151e72]
Login

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

Overview
Comment:Fix some segfaults that could have occurred after a malloc() failure. (CVS 1661)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 80151e728101c3cd5a8cf36cca2bfa661b21c746
User & Date: drh 2004-06-22 13:22:40
Context
2004-06-22
13:23
Fix error introduced during merge of main.mk. (CVS 1662) check-in: eef6da38 user: danielk1977 tags: trunk
13:22
Fix some segfaults that could have occurred after a malloc() failure. (CVS 1661) check-in: 80151e72 user: drh tags: trunk
13:12
Add crash.test script. (CVS 1660) check-in: 64a6d805 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **     PRAGMA
    25     25   **
    26         -** $Id: build.c,v 1.231 2004/06/22 12:18:32 danielk1977 Exp $
           26  +** $Id: build.c,v 1.232 2004/06/22 13:22:40 drh Exp $
    27     27   */
    28     28   #include "sqliteInt.h"
    29     29   #include <ctype.h>
    30     30   
    31     31   /*
    32     32   ** This routine is called when a new SQL statement is beginning to
    33     33   ** be parsed.  Check to see if the schema for the database needs
................................................................................
   117    117   **
   118    118   ** See also sqlite3LocateTable().
   119    119   */
   120    120   Table *sqlite3FindTable(sqlite *db, const char *zName, const char *zDatabase){
   121    121     Table *p = 0;
   122    122     int i;
   123    123     int rc = sqlite3ReadSchema(db, 0);
          124  +  assert( zName!=0 );
   124    125     for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
   125    126       int j = (i<2) ? i^1 : i;   /* Search TEMP before MAIN */
   126    127       if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
   127    128       p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1);
   128    129       if( p ) break;
   129    130     }
   130    131     return p;

Changes to src/trigger.c.

    75     75     }
    76     76   
    77     77     /* If the trigger name was unqualified, and the table is a temp table,
    78     78     ** then set iDb to 1 to create the trigger in the temporary database.
    79     79     ** If sqlite3SrcListLookup() returns 0, indicating the table does not
    80     80     ** exist, the error is caught by the block below.
    81     81     */
    82         -  if( !pTableName ) goto trigger_cleanup;
           82  +  if( !pTableName || sqlite3_malloc_failed ) goto trigger_cleanup;
    83     83     pTab = sqlite3SrcListLookup(pParse, pTableName);
    84     84     if( pName2->n==0 && pTab && pTab->iDb==1 ){
    85     85       iDb = 1;
    86     86     }
    87     87   
    88     88     /* Ensure the table name matches database name and that the table exists */
    89     89     if( sqlite3_malloc_failed ) goto trigger_cleanup;

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.385 2004/06/21 11:30:56 danielk1977 Exp $
           46  +** $Id: vdbe.c,v 1.386 2004/06/22 13:22:41 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   182    182       pElem->aMem[i].flags = MEM_Null;
   183    183     }
   184    184     p->pCurrent = pElem;
   185    185     return 0;
   186    186   }
   187    187   
   188    188   /*
   189         -** Get the AggElem currently in focus
   190         -*/
   191         -#if 0
   192         -#define AggInFocus(P)   ((P).pCurrent ? (P).pCurrent : _AggInFocus(&(P)))
   193         -static AggElem *_AggInFocus(Agg *p){
   194         -  HashElem *pElem = sqliteHashFirst(&p->hash);
   195         -  if( pElem==0 ){
   196         -    AggInsert(p,"",1);
   197         -    pElem = sqliteHashFirst(&p->hash);
   198         -  }
   199         -  return pElem ? sqliteHashData(pElem) : 0;
   200         -}
   201         -#endif
   202         -/*
   203    189   ** Store a pointer to the AggElem currently in focus in *ppElem. Return
   204    190   ** SQLITE_OK if successful, otherwise an error-code.
   205    191   */
   206    192   static int AggInFocus(Agg *p, AggElem **ppElem){
   207    193     int rc;
   208    194     int res;
   209    195   
................................................................................
  4219   4205   ** OP_AggFocus.
  4220   4206   */
  4221   4207   case OP_AggReset: {
  4222   4208     assert( !pOp->p3 || pOp->p3type==P3_KEYINFO );
  4223   4209     if( pOp->p1 ){
  4224   4210       rc = sqlite3VdbeAggReset(0, &p->agg, (KeyInfo *)pOp->p3);
  4225   4211       p->agg.nMem = pOp->p2;    /* Agg.nMem is used by AggInsert() */
  4226         -    AggInsert(&p->agg, 0, 0);
         4212  +    rc = AggInsert(&p->agg, 0, 0);
  4227   4213     }else{
  4228   4214       rc = sqlite3VdbeAggReset(db, &p->agg, (KeyInfo *)pOp->p3);
  4229   4215       p->agg.nMem = pOp->p2;
  4230   4216     }
  4231   4217     if( rc!=SQLITE_OK ){
  4232   4218       goto abort_due_to_error;
  4233   4219     }

Changes to src/vdbeaux.c.

   675    675   ** Free all resources allociated with AggElem pElem, an element of
   676    676   ** aggregate pAgg.
   677    677   */
   678    678   void freeAggElem(AggElem *pElem, Agg *pAgg){
   679    679     int i;
   680    680     for(i=0; i<pAgg->nMem; i++){
   681    681       Mem *pMem = &pElem->aMem[i];
   682         -    if( pAgg->apFunc[i] && (pMem->flags & MEM_AggCtx)!=0 ){
          682  +    if( pAgg->apFunc && pAgg->apFunc[i] && (pMem->flags & MEM_AggCtx)!=0 ){
   683    683         sqlite3_context ctx;
   684    684         ctx.pFunc = pAgg->apFunc[i];
   685    685         ctx.s.flags = MEM_Null;
   686    686         ctx.pAgg = pMem->z;
   687    687         ctx.cnt = pMem->i;
   688    688         ctx.isStep = 0;
   689    689         ctx.isError = 0;