/ Check-in [d0b6e9a0]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix a memory leak in the parser that can occur following a malloc failure. (CVS 4071)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d0b6e9a07e99cc1a7d7f61877918c9a247899996
User & Date: drh 2007-06-15 17:03:14
Context
2007-06-15
17:04
Fix typo in change comments for 3.4.0. Ticket #2416 (CVS 4072) check-in: 1f6f0330 user: drh tags: trunk
17:03
Fix a memory leak in the parser that can occur following a malloc failure. (CVS 4071) check-in: d0b6e9a0 user: drh tags: trunk
16:37
Fix an obscure memory leak in the SQL compiler.. (CVS 4070) check-in: d4ab9428 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/parse.y.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
377
378
379
380
381
382
383


384
385
386
387
388
389
390
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.229 2007/05/30 10:36:47 danielk1977 Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................

select(A) ::= oneselect(X).                      {A = X;}
%ifndef SQLITE_OMIT_COMPOUND_SELECT
select(A) ::= select(X) multiselect_op(Y) oneselect(Z).  {
  if( Z ){
    Z->op = Y;
    Z->pPrior = X;


  }
  A = Z;
}
%type multiselect_op {int}
multiselect_op(A) ::= UNION(OP).             {A = @OP;}
multiselect_op(A) ::= UNION ALL.             {A = TK_ALL;}
multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP;}







|







 







>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.230 2007/06/15 17:03:14 drh Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................

select(A) ::= oneselect(X).                      {A = X;}
%ifndef SQLITE_OMIT_COMPOUND_SELECT
select(A) ::= select(X) multiselect_op(Y) oneselect(Z).  {
  if( Z ){
    Z->op = Y;
    Z->pPrior = X;
  }else{
    sqlite3SelectDelete(X);
  }
  A = Z;
}
%type multiselect_op {int}
multiselect_op(A) ::= UNION(OP).             {A = @OP;}
multiselect_op(A) ::= UNION ALL.             {A = TK_ALL;}
multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP;}

Changes to test/fuzz_malloc.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
45
46
47
48
49
50
51
52

53


54
55
56
57
58
59
60
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file tests malloc failures in concert with fuzzy SQL generation.
#
# $Id: fuzz_malloc.test,v 1.3 2007/06/15 13:57:20 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
  puts "Skipping fuzz_malloc tests: not compiled with -DSQLITE_MEMDEBUG=1"
  finish_test
  return
}


source $testdir/fuzz_common.tcl
source $testdir/malloc_common.tcl

set ::REPEATS 20

#
# Usage: do_fuzzy_malloc_test <testname> ?<options>?
# 
#     -template
#     -sqlprep
#     -repeats
................................................................................

  sqlite_malloc_fail 0
  db close
  file delete test.db test.db-journal
  sqlite3 db test.db
  set ::prep $::fuzzyopts(-sqlprep)
  execsql $::prep


  for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {


    set ::sql [subst $::fuzzyopts(-template)]
    foreach {rc res} [catchsql "$::sql"] {}
    if {$rc==0} {
      do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
    } else {
      incr ii -1
    }







|












<



|







 







<
>

>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
..
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
60
61
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file tests malloc failures in concert with fuzzy SQL generation.
#
# $Id: fuzz_malloc.test,v 1.4 2007/06/15 17:03:15 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
  puts "Skipping fuzz_malloc tests: not compiled with -DSQLITE_MEMDEBUG=1"
  finish_test
  return
}


source $testdir/fuzz_common.tcl
source $testdir/malloc_common.tcl

set ::REPEATS 40

#
# Usage: do_fuzzy_malloc_test <testname> ?<options>?
# 
#     -template
#     -sqlprep
#     -repeats
................................................................................

  sqlite_malloc_fail 0
  db close
  file delete test.db test.db-journal
  sqlite3 db test.db
  set ::prep $::fuzzyopts(-sqlprep)
  execsql $::prep

  set jj 0
  for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
    expr srand($jj)
    incr jj
    set ::sql [subst $::fuzzyopts(-template)]
    foreach {rc res} [catchsql "$::sql"] {}
    if {$rc==0} {
      do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
    } else {
      incr ii -1
    }