var val = duckdb_value_varchar(addr(res), col.csize_t, row.csize_t) echo val free(addr(val)) Run
The code above (full example below) causes the program to echo a value and then `Error: execution of an external program failed`. I'm not sure if additional context will help clarify the situation. Does `free` require me to manually alloc memory? If not how do I properly free the resources in this context? Apologies for the many continued questions. include duckdb_wrapper proc free(p: pointer) {.importc: "free", header: "<stdlib.h>".} proc main() = var db: duckdb_database var con: duckdb_connection if (duckdb_open("test.db", db.addr) == DuckDBError): echo "Error" if (duckdb_connect(db, con.addr) == DuckDBError): echo "Error" if duckdb_query(con, "CREATE TABLE IF NOT EXISTS integers(i INTEGER, j INTEGER);", nil) == DuckDBError: echo "Error" if duckdb_query(con, "INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", nil) == DuckDBError: echo "Error" var res: duckdb_result if duckdb_query(con, "SELECT * FROM integers", addr(res)) == DuckDBError: echo "Error" # for row in 0..<3: # for col in 0..<2: # var val = duckdb_value_varchar(addr(res), col.csize_t, row.csize_t) # echo val # prints values as expected. var val = duckdb_value_varchar(addr(res), 0.idx_t, 0.idx_t) echo val free(addr(val)) # exits with error duckdb_destroy_result(addr(res)) duckdb_disconnect(addr(con)) duckdb_close(addr(db)) main() Run