SQLite

Check-in [2c1e74e58a]
Login

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

Overview
Comment:Fix a memory leak that occurs if you call sqlite_interrupt() on a query using aggregate functions where the aggregate function returns a string longer than 32 characters. (CVS 1248)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2c1e74e58a702fd2be954467a12e69a33b252831
User & Date: drh 2004-02-18 16:57:23.000
Context
2004-02-19
18:41
Fix a bug in the parser table compression algorithm of lemon. (CVS 1249) (check-in: 8d3e924975 user: drh tags: trunk)
2004-02-18
16:57
Fix a memory leak that occurs if you call sqlite_interrupt() on a query using aggregate functions where the aggregate function returns a string longer than 32 characters. (CVS 1248) (check-in: 2c1e74e58a user: drh tags: trunk)
16:56
Begin updating the architecture description to better describe how things are currently put together. (CVS 1247) (check-in: 062ecc1368 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeaux.c.
655
656
657
658
659
660
661



662
663
664
665
666
667
668
        ctx.pAgg = pMem->z;
        ctx.cnt = pMem->i;
        ctx.isStep = 0;
        ctx.isError = 0;
        (*pAgg->apFunc[i]->xFinalize)(&ctx);
        if( pMem->z!=0 && pMem->z!=pMem->zShort ){
          sqliteFree(pMem->z);



        }
      }else if( pMem->flags & MEM_Dyn ){
        sqliteFree(pMem->z);
      }
    }
    sqliteFree(pElem);
  }







>
>
>







655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
        ctx.pAgg = pMem->z;
        ctx.cnt = pMem->i;
        ctx.isStep = 0;
        ctx.isError = 0;
        (*pAgg->apFunc[i]->xFinalize)(&ctx);
        if( pMem->z!=0 && pMem->z!=pMem->zShort ){
          sqliteFree(pMem->z);
        }
        if( ctx.s.flags & MEM_Dyn ){
          sqliteFree(ctx.s.z);
        }
      }else if( pMem->flags & MEM_Dyn ){
        sqliteFree(pMem->z);
      }
    }
    sqliteFree(pElem);
  }
Changes to test/interrupt.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 Feb 8
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the sqlite_interrupt() API.
#
# $Id: interrupt.test,v 1.3 2004/02/18 01:31:54 drh Exp $


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

# Compute a checksum on the entire database.
#













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 Feb 8
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the sqlite_interrupt() API.
#
# $Id: interrupt.test,v 1.4 2004/02/18 16:57:23 drh Exp $


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

# Compute a checksum on the entire database.
#
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
}

# There are reports of a memory leak if an interrupt occurs during
# the beginning of a complex query - before the first callback.  We
# will try to reproduce it here:
#
execsql {
  UPDATE t1 SET b=round((100-rowid)/10);

}
set sql {
  SELECT sum(a.a), max(a.a), min(b.a), a.b 
  FROM t1 AS a, t1 AS b
  WHERE b.rowid=a.b
  GROUP BY 4 ORDER BY 1;
}
set sqlite_interrupt_count 1000000
execsql $sql
set max_count [expr {1000000-$sqlite_interrupt_count}]
for {set i 1} {$i<$max_count-5} {incr i 1} {
  do_test interrupt-4.$i.1 {
    set ::sqlite_interrupt_count $::i
    catchsql {
      SELECT sum(a.a), max(a.a), min(b.a), a.b 
      FROM t1 AS a, t1 AS b
      WHERE b.rowid=a.b
      GROUP BY 4 ORDER BY 1;
    }
  } {1 interrupted}
}

finish_test







|
>


<
<
<
|







|
<
<
<
<
<




142
143
144
145
146
147
148
149
150
151
152



153
154
155
156
157
158
159
160
161





162
163
164
165
}

# There are reports of a memory leak if an interrupt occurs during
# the beginning of a complex query - before the first callback.  We
# will try to reproduce it here:
#
execsql {
  CREATE TABLE t2(a,b,c);
  INSERT INTO t2 SELECT round(a/10), randstr(50,80), randstr(50,60) FROM t1;
}
set sql {



  SELECT max(min(b,c)), min(max(b,c)), a FROM t2 GROUP BY a ORDER BY a;
}
set sqlite_interrupt_count 1000000
execsql $sql
set max_count [expr {1000000-$sqlite_interrupt_count}]
for {set i 1} {$i<$max_count-5} {incr i 1} {
  do_test interrupt-4.$i.1 {
    set ::sqlite_interrupt_count $::i
    catchsql $sql





  } {1 interrupted}
}

finish_test