Skip to content

Commit e614620

Browse files
committed
fix: zero-initialize column arrays to prevent crash on error cleanup
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.
1 parent b652757 commit e614620

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/cloudsync.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,16 +1079,16 @@ bool table_add_to_context (cloudsync_context *data, table_algo algo, const char
10791079

10801080
// a table with only pk(s) is totally legal
10811081
if (ncols > 0) {
1082-
table->col_name = (char **)cloudsync_memory_alloc((uint64_t)(sizeof(char *) * ncols));
1082+
table->col_name = (char **)cloudsync_memory_zeroalloc((uint64_t)(sizeof(char *) * ncols));
10831083
if (!table->col_name) goto abort_add_table;
1084-
1085-
table->col_id = (int *)cloudsync_memory_alloc((uint64_t)(sizeof(int) * ncols));
1084+
1085+
table->col_id = (int *)cloudsync_memory_zeroalloc((uint64_t)(sizeof(int) * ncols));
10861086
if (!table->col_id) goto abort_add_table;
1087-
1088-
table->col_merge_stmt = (dbvm_t **)cloudsync_memory_alloc((uint64_t)(sizeof(void *) * ncols));
1087+
1088+
table->col_merge_stmt = (dbvm_t **)cloudsync_memory_zeroalloc((uint64_t)(sizeof(void *) * ncols));
10891089
if (!table->col_merge_stmt) goto abort_add_table;
1090-
1091-
table->col_value_stmt = (dbvm_t **)cloudsync_memory_alloc((uint64_t)(sizeof(void *) * ncols));
1090+
1091+
table->col_value_stmt = (dbvm_t **)cloudsync_memory_zeroalloc((uint64_t)(sizeof(void *) * ncols));
10921092
if (!table->col_value_stmt) goto abort_add_table;
10931093

10941094
table->col_algo = (col_algo_t *)cloudsync_memory_zeroalloc((uint64_t)(sizeof(col_algo_t) * ncols));

0 commit comments

Comments
 (0)