/ Check-in [63dd8be7]
Login

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

Overview
Comment:Fix to sqlite3DbMallocRaw() when SQLITE_OMIT_LOOKASIDE is defined so that once it fails it continues to fail. Add a comment explaining why this is important. (CVS 5804)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 63dd8be70d333c56171dfd254406abb1af685b0f
User & Date: drh 2008-10-11 17:35:16
Context
2008-10-11
17:42
Conditionally omit prototypes in pcache.h when the corresponding routines are not used. Ticket #3430. (CVS 5805) check-in: 977ae12c user: drh tags: trunk
17:35
Fix to sqlite3DbMallocRaw() when SQLITE_OMIT_LOOKASIDE is defined so that once it fails it continues to fail. Add a comment explaining why this is important. (CVS 5804) check-in: 63dd8be7 user: drh tags: trunk
17:06
Fix a OOM segfault in the BETWEEN operator parsing - discovered while using SQLITE_OMIT_LOOKASIDE. Add SQLITE_OMIT_LOOKASIDE to test_config.c and bypass lookaside.test when defined. (CVS 5803) check-in: 2a21d52c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** Memory allocation functions used throughout sqlite.
    14     14   **
    15         -** $Id: malloc.c,v 1.43 2008/10/11 15:38:30 drh Exp $
           15  +** $Id: malloc.c,v 1.44 2008/10/11 17:35:16 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <stdarg.h>
    19     19   #include <ctype.h>
    20     20   
    21     21   /*
    22     22   ** This routine runs when the memory allocator sees that the
................................................................................
   614    614     }
   615    615     return p;
   616    616   }
   617    617   
   618    618   /*
   619    619   ** Allocate and zero memory.  If the allocation fails, make
   620    620   ** the mallocFailed flag in the connection pointer.
          621  +**
          622  +** If db!=0 and db->mallocFailed is true (indicating a prior malloc
          623  +** failure on the same database connection) then always return 0.
          624  +** Hence for a particular database connection, once malloc starts
          625  +** failing, it fails consistently until mallocFailed is reset.
          626  +** This is an important assumption.  There are many places in the
          627  +** code that do things like this:
          628  +**
          629  +**         int *a = (int*)sqlite3DbMallocRaw(db, 100);
          630  +**         int *b = (int*)sqlite3DbMallocRaw(db, 200);
          631  +**         if( b ) a[10] = 9;
          632  +**
          633  +** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
          634  +** that all prior mallocs (ex: "a") worked too.
   621    635   */
   622    636   void *sqlite3DbMallocRaw(sqlite3 *db, int n){
   623    637     void *p;
   624    638   #ifndef SQLITE_OMIT_LOOKASIDE
   625    639     if( db ){
   626    640       LookasideSlot *pBuf;
   627    641       if( db->mallocFailed ){
................................................................................
   633    647         db->lookaside.nOut++;
   634    648         if( db->lookaside.nOut>db->lookaside.mxOut ){
   635    649           db->lookaside.mxOut = db->lookaside.nOut;
   636    650         }
   637    651         return (void*)pBuf;
   638    652       }
   639    653     }
          654  +#else
          655  +  if( db && db->mallocFailed ){
          656  +    return 0;
          657  +  }
   640    658   #endif
   641    659     p = sqlite3Malloc(n);
   642    660     if( !p && db ){
   643    661       db->mallocFailed = 1;
   644    662     }
   645    663     return p;
   646    664   }

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.260 2008/10/11 17:06:04 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.261 2008/10/11 17:35:16 drh Exp $
    18     18   */
    19     19   
    20     20   // All token codes are small integers with #defines that begin with "TK_"
    21     21   %token_prefix TK_
    22     22   
    23     23   // The type of the data attached to each token is Token.  This is also the
    24     24   // default type for non-terminals.
................................................................................
   799    799     A = sqlite3PExpr(pParse, TK_BETWEEN, W, 0, 0);
   800    800     if( A ){
   801    801       A->pList = pList;
   802    802     }else{
   803    803       sqlite3ExprListDelete(pParse->db, pList);
   804    804     } 
   805    805     if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
   806         -  if( !pParse->db->mallocFailed ){
   807         -    sqlite3ExprSpan(A,&W->span,&Y->span);
   808         -  }
          806  +  sqlite3ExprSpan(A,&W->span,&Y->span);
   809    807   }
   810    808   %ifndef SQLITE_OMIT_SUBQUERY
   811    809     %type in_op {int}
   812    810     in_op(A) ::= IN.      {A = 0;}
   813    811     in_op(A) ::= NOT IN.  {A = 1;}
   814    812     expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
   815    813       A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);