fix: xDel special semmantics patch (#10)

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]
This commit is contained in:
raftedproc 2023-02-17 16:04:24 +03:00 committed by GitHub
parent e90ea8bd85
commit 5f3121395c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1538,9 +1538,10 @@ int sqlite3_bind_blob(sqlite3_stmt *pStmt, int i, const void *zData, int nData,
#ifdef __sqlite_unmodified_upstream #ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, 0); return bindText(pStmt, i, zData, nData, xDel, 0);
#else #else
// xDel is a custom deallocator, due to our IT architecture it can't be // xDel is a custom deallocator and if it is not SQLITE_STATIC
// provided from other modules. // due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData, free, 0); return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, 0);
#endif #endif
} }
int sqlite3_bind_blob64(sqlite3_stmt *pStmt, int i, const void *zData, int sqlite3_bind_blob64(sqlite3_stmt *pStmt, int i, const void *zData,
@ -1598,9 +1599,10 @@ int sqlite3_bind_text(sqlite3_stmt *pStmt, int i, const char *zData, int nData,
#ifdef __sqlite_unmodified_upstream #ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8); return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
#else #else
// xDel is a custom deallocator, due to our IT architecture it can't be // xDel is a custom deallocator and if it is not SQLITE_STATIC
// provided from other modules. // due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData, free, SQLITE_UTF8); return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, SQLITE_UTF8);
#endif #endif
} }
int sqlite3_bind_text64(sqlite3_stmt *pStmt, int i, const char *zData, int sqlite3_bind_text64(sqlite3_stmt *pStmt, int i, const char *zData,