fix network abort when the project is scaled down #28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The bug was reported by @damlayildiz to be present only in Android.
In reality the bug is also in other platforms, since this code wasn't platform related.
The bug was introduced by this commit.
Basically before returning SQLITE_ERROR in case of an error the
network_result_cleanupfunction was called 2 times: the first time insidecloudsync_network_send_changes_internaland the second time innetwork_result_to_sqlite_errorcausing a double cleanup issue.Here's a before and after the fix:
Android
Before:
sqlite> .load ./cloudsync0_8_59 sqlite> SELECT cloudsync_version(); 0.8.59 sqlite> CREATE TABLE IF NOT EXISTS test_table (id TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL DEFAULT '', created_at TEXT DEFAULT CURRENT_TIMESTAMP); sqlite> .tables test_table sqlite> SELECT cloudsync_init('test_table'); 019ba3fcb7807fb0a25a9bfbaf81371a sqlite> INSERT INTO test_table (id, value) VALUES (cloudsync_uuid(), 'test1'), (cloudsync_uuid(), 'test2'); sqlite> SELECT * FROM test_table; 019ba3fc-cb71-7d61-8888-2c7afeec91fe|test1|2026-01-09 18:20:12 019ba3fc-cb71-74a8-8ead-f587682a2ef1|test2|2026-01-09 18:20:12 sqlite> SELECT cloudsync_network_init(CONNECTION_STRING); 0 sqlite> SELECT cloudsync_network_set_apikey(API_KEY); 0 sqlite> SELECT cloudsync_network_sync(); Aborted 134|emu64a:/data/local/tmp $After
sqlite> .load ./cloudsync.so sqlite> SELECT cloudsync_version();CREATE TABLE IF NOT EXISTS test_table (id TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL DEFAULT '', created_at TEXT DEFAULT CURRENT_TIMESTAMP);SELECT cloudsync_init('test_table');INSERT INTO test_table (id, value) VALUES (cloudsync_uuid(), 'test1'), (cloudsync_uuid(), 'test2');SELECT cloudsync_network_init(CONNECTION_STRING);SELECT cloudsync_network_set_apikey(API_KEY);SELECT * FROM test_table; 0.8.59 019ba414944a76e6873861d820c968d5 0 0 019ba414-9459-728a-bffa-5e115763d814|test1|2026-01-09 18:46:10 019ba414-9459-7b14-a5c8-ff9697f9f9e7|test2|2026-01-09 18:46:10 sqlite> SELECT cloudsync_network_sync(); Runtime error: cloudsync_network_send_changes unable to upload BLOB changes to remote host.MacOS
Before:
sqlite> .load ./cloudsync sqlite> SELECT cloudsync_version();CREATE TABLE IF NOT EXISTS test_table (id TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL DEFAULT '', created_at TEXT DEFAULT CURRENT_TIMESTAMP);SELECT cloudsync_init('test_table');INSERT INTO test_table (id, value) VALUES (cloudsync_uuid(), 'test1'), (cloudsync_uuid(), 'test2');SELECT cloudsync_network_init(CONNECTION_STRING);SELECT cloudsync_network_set_apikey(API_KEY);SELECT * FROM test_table; 0.8.59 019ba4171dc2715eb3ff741fa87167ac 0 0 019ba417-1dc5-7d6e-af76-401c8b5573b4|test1|2026-01-09 18:48:57 019ba417-1dc5-7bac-8631-79bee62e6ecb|test2|2026-01-09 18:48:57 sqlite> SELECT cloudsync_network_sync(); sqlite3(87025,0x1fc646c40) malloc: *** error for object 0xc7e838200: pointer being freed was not allocated sqlite3(87025,0x1fc646c40) malloc: *** set a breakpoint in malloc_error_break to debug zsh: abort sqlite3After:
sqlite> .load ./cloudsync sqlite> SELECT cloudsync_version();CREATE TABLE IF NOT EXISTS test_table (id TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL DEFAULT '', created_at TEXT DEFAULT CURRENT_TIMESTAMP);SELECT cloudsync_init('test_table');INSERT INTO test_table (id, value) VALUES (cloudsync_uuid(), 'test1'), (cloudsync_uuid(), 'test2');SELECT cloudsync_network_init(CONNECTION_STRING);SELECT cloudsync_network_set_apikey(API_KEY);SELECT * FROM test_table; 0.8.59 019ba4164827784f86f8dd450deb9cbb 0 0 019ba416-482a-78ec-9ef2-40fbf566242c|test1|2026-01-09 18:48:02 019ba416-482a-70bc-acb2-72c8edcdc76c|test2|2026-01-09 18:48:02 sqlite> SELECT cloudsync_network_sync(); Runtime error: cloudsync_network_send_changes unable to upload BLOB changes to remote host.