Skip to content

Fix/table init stale config and other issues in case of init errors#36

Merged
andinux merged 5 commits intomainfrom
fix/table-init-stale-config
Apr 2, 2026
Merged

Fix/table init stale config and other issues in case of init errors#36
andinux merged 5 commits intomainfrom
fix/table-init-stale-config

Conversation

@andinux
Copy link
Copy Markdown
Collaborator

@andinux andinux commented Apr 1, 2026

No description provided.

andinux added 5 commits April 1, 2026 15:38
When a table was dropped without calling cloudsync_cleanup(), its
settings entry persisted as an orphan. On next init, trigger creation
failed with "no such table" error. Add a database_table_exists() check
before creating triggers to gracefully skip stale entries.
The SQLite schema used PRIMARY KEY(tbl_name, key), while PostgreSQL
correctly used PRIMARY KEY(tbl_name, col_name, key). The missing
col_name caused REPLACE INTO to silently overwrite column-level
settings sharing the same (tbl_name, key) pair.
col_merge_stmt and col_value_stmt were allocated with
cloudsync_memory_alloc (unzeroed). If an error occurred before
the prepared statements were assigned, the cleanup handler called
databasevm_finalize on uninitialized garbage pointers, causing a
SIGSEGV. Changed all four column arrays to cloudsync_memory_zeroalloc
to match col_algo and col_delimiter.
When table_add_to_context_cb failed before incrementing ncols, the
column arrays (col_name, col_merge_stmt, etc.) were allocated but
never freed because table_free guarded their cleanup with
if (ncols > 0). Removed the guard so arrays are always freed.
The for loops safely execute zero iterations when ncols is 0.

Added a test that uses sqlite3_set_authorizer to force
databasevm_prepare to fail inside the callback, exercising the
error cleanup path that previously crashed on uninitialized pointers.
@andinux andinux requested a review from marcobambini April 1, 2026 23:39
@andinux andinux merged commit 974c6cb into main Apr 2, 2026
27 checks passed
@andinux andinux deleted the fix/table-init-stale-config branch April 2, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants