From 06e2db946ea84dd54cbe3a549f94d7656fac9f09 Mon Sep 17 00:00:00 2001 From: Max Gabrielsson Date: Thu, 15 Aug 2024 13:04:10 +0200 Subject: [PATCH] fix memory leak in st_asgeojson, avoid copy --- .../src/spatial/core/functions/scalar/st_asgeojson.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp b/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp index 90a17047..c4479e30 100644 --- a/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_asgeojson.cpp @@ -238,10 +238,10 @@ static void GeometryToGeoJSONFragmentFunction(DataChunk &args, ExpressionState & Geometry::Match(geom, doc, obj); size_t json_size = 0; - // TODO: YYJSON_WRITE_PRETTY - auto json_data = yyjson_mut_write(doc, 0, &json_size); - auto json_str = StringVector::AddString(result, json_data, json_size); - return json_str; + char *json_data = yyjson_mut_write_opts(doc, 0, json_allocator.GetYYJSONAllocator(), &json_size, nullptr); + // Because the arena allocator only resets after each pipeline invocation, we can safely just point into the + // arena here without needing to copy the data to the string heap with StringVector::AddString + return string_t(json_data, json_size); }); }