From 600a761e27aa25f9a5b29314bc890be10cb64283 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Tue, 28 Nov 2023 15:48:55 -0700 Subject: [PATCH] fix resource leak in to_json Signed-off-by: Andy Grove --- .../scala/com/nvidia/spark/rapids/GpuCast.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuCast.scala b/sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuCast.scala index 2f59cfba072..a732d912b8e 100644 --- a/sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuCast.scala +++ b/sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuCast.scala @@ -1113,13 +1113,15 @@ object GpuCast { } if (options.ignoreNullFieldsInStructs) { // write the value - val attrValue = castToString(cv, inputSchema(fieldIndex).dataType, options) - if (needsQuoting) { - attrColumns += quote.incRefCount() - attrColumns += escapeJsonString(attrValue) - attrColumns += quote.incRefCount() - } else { - attrColumns += attrValue + withResource(castToString(cv, inputSchema(fieldIndex).dataType, options)) { + attrValue => + if (needsQuoting) { + attrColumns += quote.incRefCount() + attrColumns += escapeJsonString(attrValue) + attrColumns += quote.incRefCount() + } else { + attrColumns += attrValue.incRefCount() + } } // now concatenate val jsonAttr = withResource(Scalar.fromString("")) { emptyString =>