SQLite

Check-in [0b8ee83f2e]
Login

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

Overview
Comment:Fix a problem in btree.c preventing an OOM error from being propagated up to the caller. (CVS 5677)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0b8ee83f2ebadab099ccd6490f6995949dafdd6f
User & Date: danielk1977 2008-09-05 05:02:47.000
Context
2008-09-05
05:29
Change pcache.test so that it works if sqlite is configured to create auto-vacuum databases by default. (CVS 5678) (check-in: 55e677569e user: danielk1977 tags: trunk)
05:02
Fix a problem in btree.c preventing an OOM error from being propagated up to the caller. (CVS 5677) (check-in: 0b8ee83f2e user: danielk1977 tags: trunk)
2008-09-04
17:17
Add support for the SQLITE_THREADSAFE=2 and SQLITE_DEFAULT_MEMSTATUS compilation options. (CVS 5676) (check-in: 85c2a58901 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btree.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.508 2008/09/02 14:07:24 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
*/
#include "btreeInt.h"












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
** 2004 April 6
**
** 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.
**
*************************************************************************
** $Id: btree.c,v 1.509 2008/09/05 05:02:47 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
*/
#include "btreeInt.h"

3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
    rc = moveToChild(pCur, pgno);
  }
  if( rc==SQLITE_OK ){
    pCur->idx = pPage->nCell - 1;
    pCur->info.nSize = 0;
    pCur->validNKey = 0;
  }
  return SQLITE_OK;
}

/* Move the cursor to the first entry in the table.  Return SQLITE_OK
** on success.  Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty.
*/
int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){







|







3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
    rc = moveToChild(pCur, pgno);
  }
  if( rc==SQLITE_OK ){
    pCur->idx = pPage->nCell - 1;
    pCur->info.nSize = 0;
    pCur->validNKey = 0;
  }
  return rc;
}

/* Move the cursor to the first entry in the table.  Return SQLITE_OK
** on success.  Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty.
*/
int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
Changes to test/malloc.test.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# which causes the N-th malloc to fail.  This special feature is used
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.64 2008/08/27 19:01:58 danielk1977 Exp $

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


# Only run these tests if memory debugging is turned on.
#







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# which causes the N-th malloc to fail.  This special feature is used
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.65 2008/09/05 05:02:47 danielk1977 Exp $

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


# Only run these tests if memory debugging is turned on.
#
608
609
610
611
612
613
614























615
616
617
618
619
620
621
622
623
  # a malloc() to allocate space to save the index key. This test case is
  # aimed at testing the response of the library to a failure in that
  # particular malloc() call.
  db eval {SELECT a FROM abc ORDER BY a} {
    db eval {UPDATE abc SET b = b - 1 WHERE a = $a}
  }
}
























# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
  # a malloc() to allocate space to save the index key. This test case is
  # aimed at testing the response of the library to a failure in that
  # particular malloc() call.
  db eval {SELECT a FROM abc ORDER BY a} {
    db eval {UPDATE abc SET b = b - 1 WHERE a = $a}
  }
}

# This test is designed to test a specific juncture in the sqlite code.
# The database set up by -sqlprep script contains a single table B-Tree
# of height 2. In the -tclbody script, the existing database connection
# is closed and a new one opened and used to insert a new row into the
# table B-Tree. By using a new connection, the outcome of a malloc() 
# failure while seeking to the right-hand side of the B-Tree to insert 
# a new record can be tested.
#
do_malloc_test 26 -sqlprep {
  BEGIN;
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES(1, randomblob(210));
  INSERT INTO t1 VALUES(1, randomblob(210));
  INSERT INTO t1 VALUES(1, randomblob(210));
  INSERT INTO t1 VALUES(1, randomblob(210));
  INSERT INTO t1 VALUES(1, randomblob(210));
  COMMIT;
} -tclbody {
  db close
  sqlite3 db test.db
  db eval { INSERT INTO t1 VALUES(1, randomblob(210)) }
}

# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test