Skip to content

Commit ed27c9e

Browse files
committed
Merge pull request #11 from cakeplus/master
Fix: inconsistent use of caml_stat_* functions
2 parents d7fd5d7 + 92ab241 commit ed27c9e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/sqlite3_stubs.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static inline void destroy_user_exception(void *user_exc_)
125125
{
126126
user_exception *user_exn = user_exc_;
127127
caml_remove_global_root(&user_exn->exn);
128-
free(user_exn);
128+
caml_stat_free(user_exn);
129129
}
130130

131131
static inline void maybe_raise_user_exception(int rc)
@@ -343,11 +343,11 @@ static inline void ref_count_finalize_dbw(db_wrap *dbw)
343343
user_function *link;
344344
for (link = dbw->user_functions; link != NULL; link = link->next) {
345345
caml_remove_generational_global_root(&link->v_fun);
346-
free(link);
346+
caml_stat_free(link);
347347
}
348348
dbw->user_functions = NULL;
349349
sqlite3_close(dbw->db);
350-
free(dbw);
350+
caml_stat_free(dbw);
351351
}
352352
}
353353

@@ -419,11 +419,11 @@ CAMLprim value caml_sqlite3_open(
419419
caml_enter_blocking_section();
420420
#ifdef SQLITE_HAS_OPEN_V2
421421
res = sqlite3_open_v2(file, &db, flags, vfs);
422-
free(vfs);
422+
caml_stat_free(vfs);
423423
#else
424424
res = sqlite3_open(file, &db);
425425
#endif
426-
free(file);
426+
caml_stat_free(file);
427427
caml_leave_blocking_section();
428428

429429
if (res) {
@@ -559,7 +559,7 @@ CAMLprim value caml_sqlite3_exec(value v_db, value v_maybe_cb, value v_sql)
559559

560560
caml_enter_blocking_section();
561561
rc = sqlite3_exec(dbw->db, sql, cb, (void *) &cbx, NULL);
562-
free(sql);
562+
caml_stat_free(sql);
563563
caml_leave_blocking_section();
564564

565565
if (rc == SQLITE_ABORT) caml_raise(*cbx.exn);
@@ -609,7 +609,7 @@ CAMLprim value caml_sqlite3_exec_no_headers(value v_db, value v_cb, value v_sql)
609609
caml_enter_blocking_section();
610610
rc =
611611
sqlite3_exec(dbw->db, sql, exec_callback_no_headers, (void *) &cbx, NULL);
612-
free(sql);
612+
caml_stat_free(sql);
613613
caml_leave_blocking_section();
614614

615615
if (rc == SQLITE_ABORT) caml_raise(*cbx.exn);
@@ -670,7 +670,7 @@ CAMLprim value caml_sqlite3_exec_not_null(value v_db, value v_cb, value v_sql)
670670
caml_enter_blocking_section();
671671
rc =
672672
sqlite3_exec(dbw->db, sql, exec_not_null_callback, (void *) &cbx, NULL);
673-
free(sql);
673+
caml_stat_free(sql);
674674
caml_leave_blocking_section();
675675

676676
if (rc == SQLITE_ABORT) {
@@ -731,7 +731,7 @@ CAMLprim value caml_sqlite3_exec_not_null_no_headers(
731731
rc =
732732
sqlite3_exec(
733733
dbw->db, sql, exec_not_null_no_headers_callback, (void *) &cbx, NULL);
734-
free(sql);
734+
caml_stat_free(sql);
735735
caml_leave_blocking_section();
736736

737737
if (rc == SQLITE_ABORT) {
@@ -751,9 +751,9 @@ static inline void finalize_stmt_gc(value v_stmt)
751751
stmt_wrap *stmtw = Sqlite3_stmtw_val(v_stmt);
752752
sqlite3_stmt *stmt = stmtw->stmt;
753753
if (stmt) sqlite3_finalize(stmt);
754-
if (stmtw->sql) free(stmtw->sql);
754+
if (stmtw->sql) caml_stat_free(stmtw->sql);
755755
ref_count_finalize_dbw(stmtw->db_wrap);
756-
free(stmtw);
756+
caml_stat_free(stmtw);
757757
}
758758

759759
CAMLprim value caml_sqlite3_stmt_finalize(value v_stmt)
@@ -1137,7 +1137,7 @@ static inline void unregister_user_function(db_wrap *db_data, value v_name)
11371137
if (prev == NULL) db_data->user_functions = link->next;
11381138
else prev->next = link->next;
11391139
caml_remove_generational_global_root(&link->v_fun);
1140-
free(link);
1140+
caml_stat_free(link);
11411141
break;
11421142
}
11431143
prev = link;
@@ -1257,4 +1257,3 @@ CAMLprim value caml_sqlite3_changes(value v_db)
12571257
check_db(dbw, "changes");
12581258
return Val_int(sqlite3_changes(dbw->db));
12591259
}
1260-

0 commit comments

Comments
 (0)