diff --git a/c/driver_manager/adbc_driver_manager.cc b/c/driver_manager/adbc_driver_manager.cc index 516bf9bbf7..e4287534df 100644 --- a/c/driver_manager/adbc_driver_manager.cc +++ b/c/driver_manager/adbc_driver_manager.cc @@ -642,8 +642,12 @@ const struct AdbcError* AdbcErrorFromArrayStream(struct ArrowArrayStream* stream return nullptr; } auto* private_data = reinterpret_cast(stream->private_data); - return private_data->private_driver->ErrorFromArrayStream(&private_data->stream, - status); + auto* error = + private_data->private_driver->ErrorFromArrayStream(&private_data->stream, status); + if (error) { + const_cast(error)->private_driver = private_data->private_driver; + } + return error; } #define INIT_ERROR(ERROR, SOURCE) \ diff --git a/go/adbc/drivermgr/adbc_driver_manager.cc b/go/adbc/drivermgr/adbc_driver_manager.cc index 516bf9bbf7..e4287534df 100644 --- a/go/adbc/drivermgr/adbc_driver_manager.cc +++ b/go/adbc/drivermgr/adbc_driver_manager.cc @@ -642,8 +642,12 @@ const struct AdbcError* AdbcErrorFromArrayStream(struct ArrowArrayStream* stream return nullptr; } auto* private_data = reinterpret_cast(stream->private_data); - return private_data->private_driver->ErrorFromArrayStream(&private_data->stream, - status); + auto* error = + private_data->private_driver->ErrorFromArrayStream(&private_data->stream, status); + if (error) { + const_cast(error)->private_driver = private_data->private_driver; + } + return error; } #define INIT_ERROR(ERROR, SOURCE) \ diff --git a/go/adbc/pkg/_tmpl/driver.go.tmpl b/go/adbc/pkg/_tmpl/driver.go.tmpl index fc489a4016..24c15f3960 100644 --- a/go/adbc/pkg/_tmpl/driver.go.tmpl +++ b/go/adbc/pkg/_tmpl/driver.go.tmpl @@ -263,7 +263,7 @@ func (cStream *cArrayStream) maybeError() C.int { if cStream.adbcErr != nil { C.{{.Prefix}}errRelease(cStream.adbcErr) } else { - cStream.adbcErr = (*C.struct_AdbcError)(C.malloc(C.ADBC_ERROR_1_1_0_SIZE)) + cStream.adbcErr = (*C.struct_AdbcError)(C.calloc(1, C.ADBC_ERROR_1_1_0_SIZE)) } cStream.adbcErr.vendor_code = C.ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA cStream.status = C.AdbcStatusCode(errToAdbcErr(cStream.adbcErr, err)) diff --git a/go/adbc/pkg/_tmpl/utils.h.tmpl b/go/adbc/pkg/_tmpl/utils.h.tmpl index ce3dba9dbc..d73f4bad71 100644 --- a/go/adbc/pkg/_tmpl/utils.h.tmpl +++ b/go/adbc/pkg/_tmpl/utils.h.tmpl @@ -83,7 +83,10 @@ AdbcStatusCode {{.Prefix}}StatementSetSubstraitPlan(struct AdbcStatement* stmt, AdbcStatusCode {{.Prefix}}DriverInit(int version, void* rawDriver, struct AdbcError* err); static inline void {{.Prefix}}errRelease(struct AdbcError* error) { - error->release(error); + if (error->release) { + error->release(error); + error->release = NULL; + } } void {{.Prefix}}_release_error(struct AdbcError* error); diff --git a/go/adbc/pkg/flightsql/driver.go b/go/adbc/pkg/flightsql/driver.go index 925fd8658e..46e096952c 100644 --- a/go/adbc/pkg/flightsql/driver.go +++ b/go/adbc/pkg/flightsql/driver.go @@ -267,7 +267,7 @@ func (cStream *cArrayStream) maybeError() C.int { if cStream.adbcErr != nil { C.FlightSQLerrRelease(cStream.adbcErr) } else { - cStream.adbcErr = (*C.struct_AdbcError)(C.malloc(C.ADBC_ERROR_1_1_0_SIZE)) + cStream.adbcErr = (*C.struct_AdbcError)(C.calloc(1, C.ADBC_ERROR_1_1_0_SIZE)) } cStream.adbcErr.vendor_code = C.ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA cStream.status = C.AdbcStatusCode(errToAdbcErr(cStream.adbcErr, err)) diff --git a/go/adbc/pkg/flightsql/utils.h b/go/adbc/pkg/flightsql/utils.h index e3b22fb737..fbdbe89a8a 100644 --- a/go/adbc/pkg/flightsql/utils.h +++ b/go/adbc/pkg/flightsql/utils.h @@ -153,7 +153,12 @@ AdbcStatusCode FlightSQLStatementSetSubstraitPlan(struct AdbcStatement* stmt, AdbcStatusCode FlightSQLDriverInit(int version, void* rawDriver, struct AdbcError* err); -static inline void FlightSQLerrRelease(struct AdbcError* error) { error->release(error); } +static inline void FlightSQLerrRelease(struct AdbcError* error) { + if (error->release) { + error->release(error); + error->release = NULL; + } +} void FlightSQL_release_error(struct AdbcError* error); diff --git a/go/adbc/pkg/panicdummy/driver.go b/go/adbc/pkg/panicdummy/driver.go index d1c143a762..c99153ccb5 100644 --- a/go/adbc/pkg/panicdummy/driver.go +++ b/go/adbc/pkg/panicdummy/driver.go @@ -267,7 +267,7 @@ func (cStream *cArrayStream) maybeError() C.int { if cStream.adbcErr != nil { C.PanicDummyerrRelease(cStream.adbcErr) } else { - cStream.adbcErr = (*C.struct_AdbcError)(C.malloc(C.ADBC_ERROR_1_1_0_SIZE)) + cStream.adbcErr = (*C.struct_AdbcError)(C.calloc(1, C.ADBC_ERROR_1_1_0_SIZE)) } cStream.adbcErr.vendor_code = C.ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA cStream.status = C.AdbcStatusCode(errToAdbcErr(cStream.adbcErr, err)) diff --git a/go/adbc/pkg/panicdummy/utils.h b/go/adbc/pkg/panicdummy/utils.h index 91d8294c4e..b8db59c227 100644 --- a/go/adbc/pkg/panicdummy/utils.h +++ b/go/adbc/pkg/panicdummy/utils.h @@ -156,7 +156,10 @@ AdbcStatusCode PanicDummyStatementSetSubstraitPlan(struct AdbcStatement* stmt, AdbcStatusCode PanicDummyDriverInit(int version, void* rawDriver, struct AdbcError* err); static inline void PanicDummyerrRelease(struct AdbcError* error) { - error->release(error); + if (error->release) { + error->release(error); + error->release = NULL; + } } void PanicDummy_release_error(struct AdbcError* error); diff --git a/go/adbc/pkg/snowflake/driver.go b/go/adbc/pkg/snowflake/driver.go index 6ca09646d4..4804e32e38 100644 --- a/go/adbc/pkg/snowflake/driver.go +++ b/go/adbc/pkg/snowflake/driver.go @@ -267,7 +267,7 @@ func (cStream *cArrayStream) maybeError() C.int { if cStream.adbcErr != nil { C.SnowflakeerrRelease(cStream.adbcErr) } else { - cStream.adbcErr = (*C.struct_AdbcError)(C.malloc(C.ADBC_ERROR_1_1_0_SIZE)) + cStream.adbcErr = (*C.struct_AdbcError)(C.calloc(1, C.ADBC_ERROR_1_1_0_SIZE)) } cStream.adbcErr.vendor_code = C.ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA cStream.status = C.AdbcStatusCode(errToAdbcErr(cStream.adbcErr, err)) diff --git a/go/adbc/pkg/snowflake/utils.h b/go/adbc/pkg/snowflake/utils.h index 23391dfd70..c679316232 100644 --- a/go/adbc/pkg/snowflake/utils.h +++ b/go/adbc/pkg/snowflake/utils.h @@ -153,7 +153,12 @@ AdbcStatusCode SnowflakeStatementSetSubstraitPlan(struct AdbcStatement* stmt, AdbcStatusCode SnowflakeDriverInit(int version, void* rawDriver, struct AdbcError* err); -static inline void SnowflakeerrRelease(struct AdbcError* error) { error->release(error); } +static inline void SnowflakeerrRelease(struct AdbcError* error) { + if (error->release) { + error->release(error); + error->release = NULL; + } +} void Snowflake_release_error(struct AdbcError* error);