Skip to content

Commit b49517c

Browse files
[c++] Follow-up to #3873 and #3928 (#3937) (#3938)
Co-authored-by: John Kerl <kerl.john.r@gmail.com>
1 parent 27d39ff commit b49517c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

libtiledbsoma/src/soma/soma_array.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ ArrowTable SOMAArray::get_enumeration_values(
394394
std::pair<ArrowArray*, ArrowSchema*>
395395
SOMAArray::get_enumeration_values_for_column(std::string column_name) {
396396
// This will throw if column name is not found
397-
std::unique_ptr<ArrowSchema> up_column_schema = arrow_schema_for_column(
398-
column_name);
399-
ArrowSchema* column_schema = up_column_schema.get();
397+
ArrowSchema* column_schema = arrow_schema_for_column(column_name);
400398

401399
// Throw if this column is not of dictionary type
402400
if (column_schema->dictionary == nullptr) {
@@ -406,6 +404,18 @@ SOMAArray::get_enumeration_values_for_column(std::string column_name) {
406404
column_name));
407405
}
408406

407+
// Release the pointers within the ArrowSchema*:
408+
column_schema->release(column_schema);
409+
// Release the ArrowSchema* itself.
410+
// We are needing to remember that this was allocated by malloc via
411+
// (as of this writing)
412+
// * SOMAArray::arrow_schema_for_column
413+
// * SOMAAttribute::arrow_schema_slot(
414+
// * ArrowAdapter::arrow_schema_from_tiledb_attribute
415+
// Follow-up audits are tracked on
416+
// https://github.com/single-cell-data/TileDB-SOMA/issues/3860
417+
free(column_schema);
418+
409419
Enumeration core_enum = get_existing_enumeration_for_column(column_name);
410420
auto value_dtype = core_enum.type();
411421

libtiledbsoma/src/soma/soma_array.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,10 @@ class SOMAArray : public SOMAObject {
308308
return schema;
309309
}
310310

311-
std::unique_ptr<ArrowSchema> arrow_schema_for_column(
312-
std::string column_name) const {
311+
ArrowSchema* arrow_schema_for_column(std::string column_name) const {
313312
for (size_t i = 0; i < columns_.size(); ++i) {
314313
if (columns_[i]->name() == column_name) {
315-
return std::unique_ptr<ArrowSchema>(
316-
columns_[i]->arrow_schema_slot(*ctx_, *arr_));
314+
return columns_[i]->arrow_schema_slot(*ctx_, *arr_);
317315
}
318316
}
319317
throw TileDBSOMAError(

0 commit comments

Comments
 (0)