Skip to content

Commit

Permalink
Arrow/Parquet: fix memleak in GetNextArrowArray() (master only)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 23, 2023
1 parent 2f555ff commit cd2a054
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3682,22 +3682,24 @@ static void OverrideArrowRelease(OGRArrowDataset *poDS, T *obj)
std::shared_ptr<arrow::MemoryPool> poMemoryPool{};
void (*pfnPreviousRelease)(T *) = nullptr;
void *pPreviousPrivateData = nullptr;

static void release(T *l_obj)
{
OverriddenPrivate *myPrivate =
static_cast<OverriddenPrivate *>(l_obj->private_data);
l_obj->private_data = myPrivate->pPreviousPrivateData;
l_obj->release = myPrivate->pfnPreviousRelease;
l_obj->release(l_obj);
delete myPrivate;
}
};

auto overriddenPrivate = new OverriddenPrivate();
overriddenPrivate->poMemoryPool = poDS->GetSharedMemoryPool();
overriddenPrivate->pPreviousPrivateData = obj->private_data;
overriddenPrivate->pfnPreviousRelease = obj->release;

obj->release = [](T *l_obj)
{
OverriddenPrivate *myPrivate =
static_cast<OverriddenPrivate *>(l_obj->private_data);
l_obj->private_data = myPrivate->pPreviousPrivateData;
l_obj->release = myPrivate->pfnPreviousRelease;
l_obj->release(l_obj);
delete myPrivate;
};
obj->release = OverriddenPrivate::release;
obj->private_data = overriddenPrivate;
}

Expand Down Expand Up @@ -4051,6 +4053,9 @@ inline int OGRArrowLayer::GetNextArrowArray(struct ArrowArrayStream *stream,
aosOptions.List());
if (out_array->length == 0)
{
if (out_array->release)
out_array->release(out_array);
memset(out_array, 0, sizeof(*out_array));
// If there are no records after filtering, start again
// with a new batch
continue;
Expand Down

0 comments on commit cd2a054

Please sign in to comment.