/ Check-in [de9f8ef6]
Login

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

Overview
Comment:Fix a memory leak that could follow an OOM condition in fts5.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1: de9f8ef6ebf036df5a558cd78fb4927da2d83ce8
User & Date: dan 2015-05-19 11:32:01
Context
2015-05-19
11:38
Update Makefile.in so that the amalgamation files built by "make sqlite3.c" include fts5. check-in: 2870a805 user: dan tags: fts5
11:32
Fix a memory leak that could follow an OOM condition in fts5. check-in: de9f8ef6 user: dan tags: fts5
2015-05-18
20:34
Improve test coverage of fts5_storage.c. check-in: 4dfe2e58 user: dan tags: fts5
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_tcl.c.

   150    150     Tcl_IncrRefCount(pEval);
   151    151     Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zToken, nToken));
   152    152     Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewIntObj(iStart));
   153    153     Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewIntObj(iEnd));
   154    154   
   155    155     rc = Tcl_EvalObjEx(p->interp, pEval, 0);
   156    156     Tcl_DecrRefCount(pEval);
          157  +  if( rc==TCL_OK ){
          158  +    rc = f5tResultToErrorCode(Tcl_GetStringResult(p->interp));
          159  +  }
   157    160   
   158    161     return rc;
   159    162   }
   160    163   
   161    164   static int xF5tApi(void*, Tcl_Interp*, int, Tcl_Obj *CONST []);
   162    165   
   163    166   static int xQueryPhraseCb(

Changes to ext/fts5/fts5_tokenize.c.

    51     51       if( (zArg[i] & 0x80)==0 ){
    52     52         p->aTokenChar[(int)zArg[i]] = (unsigned char)bTokenChars;
    53     53       }
    54     54     }
    55     55   }
    56     56   
    57     57   /*
    58         -** Create a "ascii" tokenizer.
           58  +** Delete a "ascii" tokenizer.
           59  +*/
           60  +static void fts5AsciiDelete(Fts5Tokenizer *p){
           61  +  sqlite3_free(p);
           62  +}
           63  +
           64  +/*
           65  +** Create an "ascii" tokenizer.
    59     66   */
    60     67   static int fts5AsciiCreate(
    61     68     void *pCtx, 
    62     69     const char **azArg, int nArg,
    63     70     Fts5Tokenizer **ppOut
    64     71   ){
    65     72     int rc = SQLITE_OK;
................................................................................
    81     88           }else
    82     89           if( 0==sqlite3_stricmp(azArg[i], "separators") ){
    83     90             fts5AsciiAddExceptions(p, zArg, 0);
    84     91           }else{
    85     92             rc = SQLITE_ERROR;
    86     93           }
    87     94         }
           95  +      if( rc!=SQLITE_OK ){
           96  +        fts5AsciiDelete((Fts5Tokenizer*)p);
           97  +        p = 0;
           98  +      }
    88     99       }
    89    100     }
    90    101   
    91    102     *ppOut = (Fts5Tokenizer*)p;
    92    103     return rc;
    93    104   }
    94    105   
    95         -/*
    96         -** Delete a "ascii" tokenizer.
    97         -*/
    98         -static void fts5AsciiDelete(Fts5Tokenizer *p){
    99         -  sqlite3_free(p);
   100         -}
   101         -
   102    106   
   103    107   static void asciiFold(char *aOut, const char *aIn, int nByte){
   104    108     int i;
   105    109     for(i=0; i<nByte; i++){
   106    110       char c = aIn[i];
   107    111       if( c>='A' && c<='Z' ) c += 32;
   108    112       aOut[i] = c;

Changes to ext/fts5/test/fts5_common.tcl.

    47     47     }
    48     48     set res
    49     49   }
    50     50   
    51     51   proc test_append_token {varname token iStart iEnd} {
    52     52     upvar $varname var
    53     53     lappend var $token
           54  +  return "SQLITE_OK"
    54     55   }
    55     56   proc fts5_test_tokenize {cmd} {
    56     57     set res [list]
    57     58     for {set i 0} {$i < [$cmd xColumnCount]} {incr i} {
    58     59       set tokens [list]
    59     60       $cmd xTokenize [$cmd xColumnText $i] [list test_append_token tokens]
    60     61       lappend res $tokens

Changes to ext/fts5/test/fts5tokenizer.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12         -# Tests focusing on the fts5 tokenizers
           12  +# Tests focusing on the built-in fts5 tokenizers. 
    13     13   #
    14     14   
    15     15   source [file join [file dirname [info script]] fts5_common.tcl]
    16     16   set testprefix fts5tokenizer
    17     17   
    18     18   
    19     19   do_execsql_test 1.0 {
................................................................................
    96     96       9 vw  1
    97     97     } {
    98     98       do_execsql_test 5.$tn.2.$tn2 "
    99     99         SELECT rowid FROM t1 WHERE t1 MATCH '\"$token\"'
   100    100       " $res
   101    101     }
   102    102   }
          103  +
          104  +#-------------------------------------------------------------------------
          105  +# Miscellaneous tests for the ascii tokenizer.
          106  +#
          107  +# 5.1.*: Test that the ascii tokenizer ignores non-ASCII characters in the
          108  +#        'separators' option. But unicode61 does not.
          109  +#
          110  +# 5.2.*: An option without an argument is an error.
          111  +#
          112  +
          113  +do_test 5.1.1 {
          114  +  execsql "
          115  +    CREATE VIRTUAL TABLE a1 USING fts5(x, tokenize=`ascii separators '\u1234'`);
          116  +    INSERT INTO a1 VALUES('abc\u1234def');
          117  +  "
          118  +  execsql { SELECT rowid FROM a1 WHERE a1 MATCH 'def' } 
          119  +} {}
          120  +
          121  +do_test 5.1.2 {
          122  +  execsql "
          123  +    CREATE VIRTUAL TABLE a2 USING fts5(
          124  +        x, tokenize=`unicode61 separators '\u1234'`);
          125  +    INSERT INTO a2 VALUES('abc\u1234def');
          126  +  "
          127  +  execsql { SELECT rowid FROM a2 WHERE a2 MATCH 'def' } 
          128  +} {1}
          129  +
          130  +do_catchsql_test 5.2 {
          131  +  CREATE VIRTUAL TABLE a3 USING fts5(x, y, tokenize = 'ascii tokenchars');
          132  +} {1 {error in tokenizer constructor}}
          133  +do_catchsql_test 5.3 {
          134  +  CREATE VIRTUAL TABLE a3 USING fts5(x, y, tokenize = 'ascii opt arg');
          135  +} {1 {error in tokenizer constructor}}
   103    136   
   104    137   finish_test
   105    138