Skip to content

Commit f6405fe

Browse files
committed
Context is now correctly deallocated
1 parent 2f9279b commit f6405fe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/sqlite-vector.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ void *vector_context_create (void) {
735735
return (void *)ctx;
736736
}
737737

738+
void vector_context_free (void *p) {
739+
if (p) {
740+
vector_context *ctx = (vector_context *)p;
741+
for (int i=0; i<ctx->table_count; ++i) {
742+
if (ctx->tables[i].t_name) sqlite3_free(ctx->tables[i].t_name);
743+
if (ctx->tables[i].c_name) sqlite3_free(ctx->tables[i].c_name);
744+
}
745+
sqlite3_free(p);
746+
}
747+
}
748+
738749
table_context *vector_context_lookup (vector_context *ctx, const char *table_name, const char *column_name) {
739750
for (int i=0; i<ctx->table_count; ++i) {
740751
// tname and cname can be NULL after adding vector_cleanup function
@@ -1882,7 +1893,7 @@ SQLITE_VECTOR_API int sqlite3_vector_init (sqlite3 *db, char **pzErrMsg, const s
18821893
return SQLITE_NOMEM;
18831894
}
18841895

1885-
rc = sqlite3_create_function(db, "vector_version", 0, SQLITE_UTF8, ctx, vector_version, NULL, NULL);
1896+
rc = sqlite3_create_function_v2(db, "vector_version", 0, SQLITE_UTF8, ctx, vector_version, NULL, NULL, vector_context_free);
18861897
if (rc != SQLITE_OK) goto cleanup;
18871898

18881899
rc = sqlite3_create_function(db, "vector_backend", 0, SQLITE_UTF8, ctx, vector_backend, NULL, NULL);

src/sqlite-vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
extern "C" {
2525
#endif
2626

27-
#define SQLITE_VECTOR_VERSION "0.8.7"
27+
#define SQLITE_VECTOR_VERSION "0.8.8"
2828

2929
SQLITE_VECTOR_API int sqlite3_vector_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
3030

0 commit comments

Comments
 (0)