Skip to content

Commit

Permalink
sql: too many autogenerated ids leads to SEGFAULT
Browse files Browse the repository at this point in the history
This probleam appeared because region was cleaned twice: once in
sqlite3VdbeHalt() and once in sqlite3VdbeDelete() which was
executed during sqlite3_finalize(). Autogenerated ids that were
saved there, were fetched after sqlite3VdbeHalt() and before
sqlite3_finalize(). In this patch region cleaning in
sqlite3VdbeHalt() were removed.

Follow up #2618
Follow up #3199
  • Loading branch information
ImeevMA authored and Gerold103 committed Nov 19, 2018
1 parent 9e22a12 commit 6128bdc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/box/sql/vdbe.c
Expand Up @@ -2911,12 +2911,8 @@ case OP_MakeRecord: {
* memory shouldn't be reused until it is written into WAL.
*
* However, if memory for ephemeral space is allocated
* on region, it will be freed only in vdbeHalt() routine.
* It is the only way to free this region memory,
* since ephemeral spaces don't have nothing in common
* with txn routine and region memory won't be released
* after txn_commit() or txn_rollback() as it happens
* with ordinary spaces.
* on region, it will be freed only in sqlite3_finalize()
* routine.
*/
if (bIsEphemeral) {
rc = sqlite3VdbeMemClearAndResize(pOut, nByte);
Expand Down
6 changes: 0 additions & 6 deletions src/box/sql/vdbeaux.c
Expand Up @@ -2498,12 +2498,6 @@ sqlite3VdbeHalt(Vdbe * p)
p->rc = SQLITE_NOMEM_BKPT;
}

/* Release all region memory which was allocated
* to hold tuples to be inserted into ephemeral spaces.
*/
if (!box_txn())
fiber_gc();

assert(db->nVdbeActive > 0 || box_txn() ||
p->anonymous_savepoint == NULL);
return (p->rc == SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
Expand Down
16 changes: 16 additions & 0 deletions test/sql/iproto.result
Expand Up @@ -794,6 +794,22 @@ res.rows
- - [[{'name': 'space_id', 'type': 'unsigned'}, {'name': 'lsn', 'type': 'unsigned'},
{'name': 'tuple', 'type': 'array'}]]
...
-- Too many autogenerated ids leads to SEGFAULT.
cn = remote.connect(box.cfg.listen)
---
...
box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT)')
---
...
for i = 0, 1000 do cn:execute("INSERT INTO t1 VALUES (null)") end
---
...
_ = cn:execute("INSERT INTO t1 SELECT NULL from t1")
---
...
box.sql.execute('DROP TABLE t1')
---
...
cn:close()
---
...
Expand Down
7 changes: 7 additions & 0 deletions test/sql/iproto.test.lua
Expand Up @@ -261,6 +261,13 @@ _ = cn:execute("EXPLAIN SELECT 1;")
res = cn:execute('select "format" from "_space" limit 1;')
res.rows

-- Too many autogenerated ids leads to SEGFAULT.
cn = remote.connect(box.cfg.listen)
box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT)')
for i = 0, 1000 do cn:execute("INSERT INTO t1 VALUES (null)") end
_ = cn:execute("INSERT INTO t1 SELECT NULL from t1")
box.sql.execute('DROP TABLE t1')

cn:close()

box.schema.user.revoke('guest', 'read,write,execute', 'universe')
Expand Down

0 comments on commit 6128bdc

Please sign in to comment.