Skip to content

Commit

Permalink
[c++] Address final valgrind issue (#2403)
Browse files Browse the repository at this point in the history
* Release (default) allocation of private_data before point to ours

* Remove unnecessary buffer set up done by nanoarrow

Also removes one function no longer needed

* White-space only commit because of clang-format
  • Loading branch information
eddelbuettel authored Apr 8, 2024
1 parent 95e3156 commit e0e3fa4
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions libtiledbsoma/src/utils/arrow_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,6 @@ std::pair<const void*, std::size_t> ArrowAdapter::_get_data_and_length(
}
}

bool ArrowAdapter::_isstr(const char* format) {
if ((strcmp(format, "U") == 0) || (strcmp(format, "Z") == 0) ||
(strcmp(format, "u") == 0) || (strcmp(format, "z") == 0)) {
return true;
}
return false;
}

inline void exitIfError(const ArrowErrorCode ec, const std::string& msg) {
if (ec != NANOARROW_OK)
throw TileDBSOMAError(
Expand Down Expand Up @@ -358,6 +350,9 @@ ArrowAdapter::to_arrow(std::shared_ptr<ColumnBuffer> column) {
// After allocating and initializing via nanoarrow we
// hook our custom release function in
array->release = &release_array;
if (array->private_data != nullptr) { // as we use nanoarrow's init
free(array->private_data); // free what was allocated before
} // assigning our ArrowBuffer pointer
array->private_data = (void*)arrow_buffer;

LOG_TRACE(fmt::format(
Expand Down Expand Up @@ -445,10 +440,7 @@ ArrowAdapter::to_arrow(std::shared_ptr<ColumnBuffer> column) {
exitIfError(
ArrowArrayAllocateChildren(dict_arr, 0),
"Bad array children alloc");
const int n_buf = ArrowAdapter::_isstr(dict_sch->format) == true ? 3 :
2;
dict_arr->buffers = (const void**)malloc(sizeof(void*) * n_buf);
dict_arr->buffers[0] = nullptr; // validity: none here
// hook up our custom release function
dict_arr->release = &release_array;

// TODO string types currently get the data and offset
Expand Down

0 comments on commit e0e3fa4

Please sign in to comment.