/ Check-in [3538a4e3]
Login

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

Overview
Comment:Make sure SQLITE_NOMEM is reported out on a malloc failure in an ATTACH even if the malloc failure reports within a nested calls to sqlite3_prepare(). (CVS 3164)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3538a4e30fb5131b461bb0cf72cada63e9724e14
User & Date: drh 2006-04-05 11:57:37
Context
2006-04-05
12:15
Preparing for the release of version 3.3.5. (CVS 3165) check-in: 159fb92b user: drh tags: trunk
11:57
Make sure SQLITE_NOMEM is reported out on a malloc failure in an ATTACH even if the malloc failure reports within a nested calls to sqlite3_prepare(). (CVS 3164) check-in: 3538a4e3 user: drh tags: trunk
01:08
Add documentation on new sqlite_authorizer callback types. Ticket #1744. (CVS 3163) check-in: fdbff3f1 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/attach.c.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
181
182
183
184
185
186
187




188

189
190
191
192
193
194
195
**    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 contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.49 2006/01/24 12:09:18 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** Resolve an expression that was part of an ATTACH or DETACH statement. This
** is slightly different from resolving a normal SQL expression, because simple
** identifiers are treated as strings, not possible column names or aliases.
................................................................................
    if( db->aDb[iDb].pBt ){
      sqlite3BtreeClose(db->aDb[iDb].pBt);
      db->aDb[iDb].pBt = 0;
      db->aDb[iDb].pSchema = 0;
    }
    sqlite3ResetInternalSchema(db, 0);
    db->nDb = iDb;




    sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);

    goto attach_error;
  }
  
  return;

attach_error:
  /* Return an error if we get here */







|







 







>
>
>
>
|
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
**    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 contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.50 2006/04/05 11:57:37 drh Exp $
*/
#include "sqliteInt.h"

/*
** Resolve an expression that was part of an ATTACH or DETACH statement. This
** is slightly different from resolving a normal SQL expression, because simple
** identifiers are treated as strings, not possible column names or aliases.
................................................................................
    if( db->aDb[iDb].pBt ){
      sqlite3BtreeClose(db->aDb[iDb].pBt);
      db->aDb[iDb].pBt = 0;
      db->aDb[iDb].pSchema = 0;
    }
    sqlite3ResetInternalSchema(db, 0);
    db->nDb = iDb;
    if( rc==SQLITE_NOMEM ){
      sqlite3MallocFailed();
      sqlite3_snprintf(127, zErr, "out of memory");
    }else{
      sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);
    }
    goto attach_error;
  }
  
  return;

attach_error:
  /* Return an error if we get here */

Changes to test/malloc.test.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
508
509
510
511
512
513
514




















515
516
517
518
519
520
521
522
523
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) 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.30 2006/01/24 10:58:23 danielk1977 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]==""} {
................................................................................
  set msg
} -cleanup {
  if {[info exists ::STMT]} {
    sqlite3_finalize $::STMT
  }
}
unset static_string





















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

sqlite_malloc_fail 0
finish_test







|







 







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









10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) 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.31 2006/04/05 11:57:37 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]==""} {
................................................................................
  set msg
} -cleanup {
  if {[info exists ::STMT]} {
    sqlite3_finalize $::STMT
  }
}
unset static_string

# Make sure SQLITE_NOMEM is reported out on an ATTACH failure even
# when the malloc failure occurs within the nested parse.
#
do_malloc_test 20 -tclprep {
  db close
  file delete -force test2.db test2.db-journal
  sqlite3 db test2.db
  db eval {CREATE TABLE t1(x);}
  db close
} -tclbody {
  if {[catch {sqlite3 db test.db}]} {
    error "out of memory"
  }
} -sqlbody {
  ATTACH DATABASE 'test2.db' AS t2;
  SELECT * FROM t1;
  DETACH DATABASE t2;
} 


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

sqlite_malloc_fail 0
finish_test