Skip to content

Commit

Permalink
Merge pull request #345 from TileDB-Inc/smr/asan-failures
Browse files Browse the repository at this point in the history
Fix ASAN failures.
  • Loading branch information
shaunrd0 authored Aug 22, 2024
2 parents 0b1650f + fefe73d commit 3e72fa5
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 158 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tiledb-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,4 @@ jobs:

# Tests TileDB-Go
- name: Running examples using address sanitizer flags
continue-on-error: true
run: ./.github/scripts/build_with_sanitizer_and_run.sh
68 changes: 43 additions & 25 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,13 @@ func (a *Array) NonEmptyDomain() ([]NonEmptyDomain, bool, error) {
if err != nil {
return nil, false, err
}
defer schema.Free()

domain, err := schema.Domain()
if err != nil {
return nil, false, err
}
defer domain.Free()

ndims, err := domain.NDim()
if err != nil {
Expand All @@ -389,41 +391,51 @@ func (a *Array) NonEmptyDomain() ([]NonEmptyDomain, bool, error) {
isDomainEmpty := true
nonEmptyDomains := make([]NonEmptyDomain, 0)
for dimIdx := uint(0); dimIdx < ndims; dimIdx++ {
dimension, err := domain.DimensionFromIndex(dimIdx)
if err != nil {
return nil, false, err
}
// Wrapped in a function so `dimension` will be cleaned up with defer each time the function completes.
err := func() error {
dimension, err := domain.DimensionFromIndex(dimIdx)
if err != nil {
return err
}
defer dimension.Free()

dimensionType, err := dimension.Type()
if err != nil {
return nil, false, err
}
dimensionType, err := dimension.Type()
if err != nil {
return err
}

tmpDimension, tmpDimensionPtr, err := dimensionType.MakeSlice(uint64(2))
if err != nil {
return nil, false, err
}
tmpDimension, tmpDimensionPtr, err := dimensionType.MakeSlice(uint64(2))
if err != nil {
return err
}

var isEmpty C.int32_t
ret := C.tiledb_array_get_non_empty_domain_from_index(
a.context.tiledbContext,
a.tiledbArray,
(C.uint32_t)(dimIdx),
tmpDimensionPtr, &isEmpty)
if ret != C.TILEDB_OK {
return nil, false, fmt.Errorf("Error in getting non empty domain for dimension: %s", a.context.LastError())
}
var isEmpty C.int32_t
ret := C.tiledb_array_get_non_empty_domain_from_index(
a.context.tiledbContext,
a.tiledbArray,
(C.uint32_t)(dimIdx),
tmpDimensionPtr, &isEmpty)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error in getting non empty domain for dimension: %s", a.context.LastError())
}

if isEmpty == 1 {
return nil
}

if isEmpty == 1 {
continue
} else {
// If at least one domain for a dimension is empty the union of domains is non-empty
isDomainEmpty = false
nonEmptyDomain, err := getNonEmptyDomainForDim(dimension, tmpDimension)
if err != nil {
return nil, false, err
return err
}
nonEmptyDomains = append(nonEmptyDomains, *nonEmptyDomain)

return nil
}()

if err != nil {
return nil, false, err
}
}

Expand Down Expand Up @@ -531,11 +543,13 @@ func (a *Array) NonEmptyDomainVarFromName(dimName string) (*NonEmptyDomain, bool
if err != nil {
return nil, false, err
}
defer schema.Free()

domain, err := schema.Domain()
if err != nil {
return nil, false, err
}
defer domain.Free()

hasDim, err := domain.HasDimension(dimName)
if err != nil {
Expand All @@ -550,6 +564,7 @@ func (a *Array) NonEmptyDomainVarFromName(dimName string) (*NonEmptyDomain, bool
if err != nil {
return nil, false, fmt.Errorf("could not get dimension: %s", dimName)
}
defer dimension.Free()

dimType, err := dimension.Type()
if err != nil {
Expand Down Expand Up @@ -630,16 +645,19 @@ func (a *Array) NonEmptyDomainVarFromIndex(dimIdx uint) (*NonEmptyDomain, bool,
if err != nil {
return nil, false, err
}
defer schema.Free()

domain, err := schema.Domain()
if err != nil {
return nil, false, err
}
defer domain.Free()

dimension, err := domain.DimensionFromIndex(dimIdx)
if err != nil {
return nil, false, fmt.Errorf("Could not get dimension having index: %d", dimIdx)
}
defer dimension.Free()

dimType, err := dimension.Type()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewContextFromMap(cfgMap map[string]string) (*Context, error) {
if err != nil {
return nil, err
}
defer config.Free()
for k, v := range cfgMap {
if err := config.Set(k, v); err != nil {
// The value is not included in the error message in case it is sensitive,
Expand Down
2 changes: 2 additions & 0 deletions dimension_label_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ func (q *Query) getDimensionLabelDataType(labelName string) (Datatype, error) {
if err != nil {
return 0, fmt.Errorf("Could not get schema for getDimensionLabelDatatype: %s", err)
}
defer schema.Free()

dimLabel, err := schema.DimensionLabelFromName(labelName)
if err != nil {
return 0, fmt.Errorf("Could not get dimension label %s for getDimensionLabelDatatype: %s", labelName, err)
}
defer dimLabel.Free()

datatype, err := dimLabel.Type()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions examples_lib/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ func createEncryptedArray(dir string) {

rowDim, err := tiledb.NewDimension(ctx, "rows", tiledb.TILEDB_INT32, []int32{1, 4}, int32(4))
checkError(err)
defer rowDim.Free()
colDim, err := tiledb.NewDimension(ctx, "cols", tiledb.TILEDB_INT32, []int32{1, 4}, int32(4))
checkError(err)
defer colDim.Free()
err = domain.AddDimensions(rowDim, colDim)
checkError(err)

Expand Down Expand Up @@ -113,6 +115,7 @@ func readEncryptedArray(dir string) {
// Slice only rows 1, 2 and cols 2, 3, 4
subarray, err := array.NewSubarray()
checkError(err)
defer subarray.Free()
err = subarray.SetSubArray([]int32{1, 2, 2, 4})
checkError(err)

Expand Down
1 change: 0 additions & 1 deletion examples_lib/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package examples_lib

import (
"fmt"

tiledb "github.com/TileDB-Inc/TileDB-Go"
)

Expand Down
1 change: 0 additions & 1 deletion examples_lib/quickstart_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package examples_lib

import (
"fmt"

tiledb "github.com/TileDB-Inc/TileDB-Go"
"github.com/TileDB-Inc/TileDB-Go/bytesizes"
)
Expand Down
2 changes: 2 additions & 0 deletions examples_lib/vacuum.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func consolidateVacuum(dir string) {

ctx, err := tiledb.NewContext(nil)
checkError(err)
defer ctx.Free()

// Prepare the array for reading
array, err := tiledb.NewArray(ctx, dir)
Expand All @@ -194,6 +195,7 @@ func consolidateVacuum(dir string) {

config, err := tiledb.NewConfig()
checkError(err)
defer config.Free()

err = config.Set("sm.consolidation.buffer_size", "8")
checkError(err)
Expand Down
2 changes: 2 additions & 0 deletions examples_lib/writing_dense_global_expansion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ func createDenseGlobalExpansionArray(dir string) {

rowDim, err := tiledb.NewDimension(ctx, "rows", tiledb.TILEDB_INT32, []int32{1, 4}, int32(2))
checkError(err)
defer rowDim.Free()
colDim, err := tiledb.NewDimension(ctx, "cols", tiledb.TILEDB_INT32, []int32{1, 3}, int32(2))
checkError(err)
defer colDim.Free()
err = domain.AddDimensions(rowDim, colDim)
checkError(err)

Expand Down
2 changes: 1 addition & 1 deletion examples_lib/writing_sparse_multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func createMultipleWritesSparseArray(dir string) {
// with domain [1,4].
domain, err := tiledb.NewDomain(ctx)
checkError(err)
defer ctx.Free()
defer domain.Free()

rowDim, err := tiledb.NewDimension(ctx, "rows", tiledb.TILEDB_INT32, []int32{1, 4}, int32(4))
checkError(err)
Expand Down
Loading

0 comments on commit 3e72fa5

Please sign in to comment.