SQLite

Check-in [bd341a103c]
Login

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

Overview
Comment:Make sure nested queries with USING clauses do not leak memory. Preliminary fix for ticket #3911. (CVS 6750)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bd341a103c25395b1189d05edebfe4af8a943941
User & Date: drh 2009-06-12 03:27:27.000
Context
2009-06-12
03:47
An additional memory leak in the parser fixed. Ticket #3911. (CVS 6751) (check-in: 6197b49271 user: drh tags: trunk)
03:27
Make sure nested queries with USING clauses do not leak memory. Preliminary fix for ticket #3911. (CVS 6750) (check-in: bd341a103c user: drh tags: trunk)
02:27
Modifications to the parser to eliminate unreachable code. (CVS 6749) (check-in: 457e0b245b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/select.c.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.523 2009/06/01 16:53:10 shane Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.524 2009/06/12 03:27:27 drh Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
2793
2794
2795
2796
2797
2798
2799

2800
2801
2802
2803
2804
2805
2806
      }
    }

    /* Transfer the FROM clause terms from the subquery into the
    ** outer query.
    */
    for(i=0; i<nSubSrc; i++){

      pSrc->a[i+iFrom] = pSubSrc->a[i];
      memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
    }
    pSrc->a[iFrom].jointype = jointype;
  
    /* Now begin substituting subquery result set expressions for 
    ** references to the iParent in the outer query.







>







2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
      }
    }

    /* Transfer the FROM clause terms from the subquery into the
    ** outer query.
    */
    for(i=0; i<nSubSrc; i++){
      sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
      pSrc->a[i+iFrom] = pSubSrc->a[i];
      memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
    }
    pSrc->a[iFrom].jointype = jointype;
  
    /* Now begin substituting subquery result set expressions for 
    ** references to the iParent in the outer query.
Added test/tkt3911.test.




















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 2009 June 11
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests to verify ticket #3911 is fixed.
#
# $Id: tkt3911.test,v 1.1 2009/06/12 03:27:28 drh Exp $

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

do_test tkt3911.1 {
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t1 VALUES(11,12);

    CREATE TABLE t2(b,c);
    INSERT INTO t2 VALUES(2,3);
    INSERT INTO t2 VALUES(22,23);

    SELECT * FROM t1 JOIN t2 USING(b);
  }
} {1 2 3}
do_test tkt3911.2 {
  db eval {
    SELECT * FROM t1 JOIN (t2) AS x USING (b);
  }
} {1 2 3}
do_test tkt3911.3 {
  db eval {
    SELECT * FROM t1 JOIN (SELECT * FROM t2) AS x USING (b);
  }
} {1 2 3}

do_test tkt3911.4 {
  db eval {
    CREATE TABLE t3(m,a);
    INSERT INTO t3 VALUES('one',1);
    INSERT INTO t3 VALUES('two',2);

    SELECT * FROM t3 JOIN (SELECT * FROM t1 NATURAL JOIN t2) AS x USING(a);
  }
} {one 1 2 3}
do_test tkt3911.5 {
  db eval {
    SELECT * FROM t3 JOIN (SELECT * FROM t1 JOIN t2 USING (b)) AS x USING(a);
  }
} {one 1 2 3}

finish_test