On 10/28/15, Lohmann, Niels, Dr. (CQTN) <niels.lohmann at carmeq.com> wrote:
> Hi there,
>
> unfortunately, I cannot create a better stack trace on short notice.
>
> However, you may be able to reproduce the problem as follows:
>
> - Create an in-memory database.
> - Release it.
> - Create an in-memory database.
> - Release it.
>
> The first run succeeds, whereas the second one yields a crash when using
> "?cache=shared".
>

My test program is shown below.  It works fine for me.  Perhaps you
can suggest a modification that leads to a crash.

-------------------------  begin attachment -----------------------------
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

/* Check a return code to verify it is SQLITE_OK.  If it is not,
** print an error and panic. */
static void checkReturn(int rc){
  if( rc!=SQLITE_OK ){
    printf("Error: (%d) %s\n", rc, sqlite3_errstr(rc));
    exit(1);
  }
}

/* Print a single row of output from an sqlite3_exec() query */
static int execCallback(void *notUsed, int argc, char **argv, char **colv){
  int i;
  for(i=0; i<argc; i++){
    printf("%s: %s\n", colv[i], argv[i]);
  }
  printf("\n");
  return 0;
}

int main(int argc, char **argv){
  sqlite3 *db1 = 0;
  sqlite3 *db2 = 0;
  int rc;

  rc = sqlite3_open_v2("file::memory:?cache=shared", &db1,
                       SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
                         | SQLITE_OPEN_URI, 0);
  checkReturn(rc);
  sqlite3_exec(db1,
     "CREATE TABLE t1(a,b,c);"
     "WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c wHERE x<10)"
     " INSERT INTO t1(a,b,c) SELECT x, 100-x, printf('abc%02dxyz',x) FROM c;",
     0, 0, 0);
  rc = sqlite3_open_v2("file::memory:?cache=shared", &db2,
                       SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
                         | SQLITE_OPEN_URI, 0);
  checkReturn(rc);
  sqlite3_exec(db2, "SELECT * FROM t1 LIMIT 3", execCallback, 0, 0);
  printf("---- about to close and reopen db2\n");
  sqlite3_close(db2);
  rc = sqlite3_open_v2("file::memory:?cache=shared", &db2,
                       SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
                         | SQLITE_OPEN_URI, 0);
  checkReturn(rc);
  sqlite3_exec(db2, "SELECT * FROM t1 LIMIT 3", execCallback, 0, 0);
  return 0;
}
------------------------ end attachment -----------------------


-- 
D. Richard Hipp
drh at sqlite.org

Reply via email to