Skip to content

Commit

Permalink
fix: xDel special semmantics patch
Browse files Browse the repository at this point in the history
    Sqlite has a number of special custom memory deallocators, namely SQLITE_STATIC and SQLITE_TRANSIENT. Sqlite calls noop freeing memory with the special deallocators.
    Sqlite virtual tables, e.g. FTS5 implicitly creates aux tables. There are number of SQLITE_STATIC allocated empty lines or 0 size blobs that were previously freed with free. This free op spoils sqlite virtual table state  and renders VT unusable [fixes VM-239]
  • Loading branch information
raftedproc committed Feb 17, 2023
1 parent e90ea8b commit 126aae1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/vdbeapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,10 @@ int sqlite3_bind_blob(sqlite3_stmt *pStmt, int i, const void *zData, int nData,
#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, 0);
#else
// xDel is a custom deallocator, due to our IT architecture it can't be
// provided from other modules.
return bindText(pStmt, i, zData, nData, free, 0);
// xDel is a custom deallocator and if it is not SQLITE_STATIC
// due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, 0);
#endif
}
int sqlite3_bind_blob64(sqlite3_stmt *pStmt, int i, const void *zData,
Expand Down Expand Up @@ -1598,9 +1599,10 @@ int sqlite3_bind_text(sqlite3_stmt *pStmt, int i, const char *zData, int nData,
#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
#else
// xDel is a custom deallocator, due to our IT architecture it can't be
// provided from other modules.
return bindText(pStmt, i, zData, nData, free, SQLITE_UTF8);
// xDel is a custom deallocator and if it is not SQLITE_STATIC
// due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, SQLITE_UTF8);
#endif
}
int sqlite3_bind_text64(sqlite3_stmt *pStmt, int i, const char *zData,
Expand Down

0 comments on commit 126aae1

Please sign in to comment.