From 8ca4261f49b2b6111a211ff896cdfedc39ddbb3b Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Sat, 21 Sep 2024 11:13:10 -0500 Subject: [PATCH 1/2] fix: close ResultSet before closing Statement suppresses "JDBC resources leaked" warning with agroal --- .../main/kotlin/org/jetbrains/exposed/sql/AbstractQuery.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/AbstractQuery.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/AbstractQuery.kt index d4d7a41e17..372ba99dab 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/AbstractQuery.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/AbstractQuery.kt @@ -103,7 +103,9 @@ abstract class AbstractQuery>( set(value) { field = value if (!field) { - rs.statement?.close() + val statement = rs.statement + rs.close() + statement?.close() transaction.openResultSetsCount-- } } From 42017f55a3c6fcb2fd3827642b95151adc139dd9 Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Mon, 23 Sep 2024 11:16:28 -0500 Subject: [PATCH 2/2] fix: close ResultSet before closing Statement address review comments --- .../src/main/kotlin/org/jetbrains/exposed/sql/ExplainQuery.kt | 4 +++- .../org/jetbrains/exposed/sql/statements/InsertStatement.kt | 1 + .../jetbrains/exposed/sql/statements/ReturningStatement.kt | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ExplainQuery.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ExplainQuery.kt index 17a4f36bc3..273f0ad0e7 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ExplainQuery.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ExplainQuery.kt @@ -43,7 +43,9 @@ open class ExplainQuery( set(value) { field = value if (!field) { - rs.statement?.close() + val statement = rs.statement + rs.close() + statement?.close() transaction.openResultSetsCount-- } } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt index 6cbeda99f6..1f54a8534a 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt @@ -199,6 +199,7 @@ open class InsertStatement( return inserted.apply { insertedCount = this resultedValues = processResults(rs, this) + rs?.close() } } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/ReturningStatement.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/ReturningStatement.kt index 0a76fa25a4..554e1d4a8e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/ReturningStatement.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/ReturningStatement.kt @@ -45,7 +45,9 @@ open class ReturningStatement( set(value) { field = value if (!field) { - rs.statement?.close() + val statement = rs.statement + rs.close() + statement?.close() transaction.openResultSetsCount-- } }