Skip to content

Commit e83a721

Browse files
committed
fix(unittest): avoid a memory leak from do_test_dbutils
1 parent d3d66ec commit e83a721

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/unit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ bool do_test_dbutils (void) {
18961896
sqlite3_cloudsync_init(db, NULL, NULL);
18971897
cloudsync_set_payload_apply_callback(db, unittest_payload_apply_rls_callback);
18981898

1899+
// test context create and free
18991900
void *data = cloudsync_context_create(db);
19001901
if (!data) return false;
19011902

@@ -2085,6 +2086,7 @@ bool do_test_dbutils (void) {
20852086
finalize:
20862087
if (rc != SQLITE_OK) printf("%s\n", sqlite3_errmsg(db));
20872088
db = close_db(db);
2089+
if (data) cloudsync_context_free(data);
20882090
return (rc == SQLITE_OK);
20892091
}
20902092

@@ -6284,15 +6286,15 @@ int main (int argc, const char * argv[]) {
62846286
result += test_report("Test Alter Table 3:", do_test_alter(3, 3, print_result, cleanup_databases));
62856287

62866288
finalize:
6287-
printf("\n");
62886289
if (rc != SQLITE_OK) printf("%s (%d)\n", (db) ? sqlite3_errmsg(db) : "N/A", rc);
62896290
db = close_db(db);
62906291

62916292
cloudsync_memory_finalize();
62926293

62936294
sqlite3_int64 memory_used = sqlite3_memory_used();
6295+
result += test_report("Memory leak check:", memory_used == 0);
62946296
if (memory_used > 0) {
6295-
printf("Memory leaked: %lld B\n", memory_used);
6297+
printf("\tleaked: %lld B\n", memory_used);
62966298
result++;
62976299
}
62986300

0 commit comments

Comments
 (0)