[CONJ-971] A static analysis has found a resource leak Created: 2022-05-09  Updated: 2022-05-13  Resolved: 2022-05-13

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 3.0.3, 3.0.4
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Zuzana Miklankova Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

The static analysis tool found a possible resource leak, which I am not sure if it is a false positive or not:

src/main/java/org/mariadb/jdbc/pool/Pool.java:
102 Statement stmt = idleConnections.getFirst().getConnection().createStatement();
(Variable "stmt" going out of scope leaks the resource it refers to. )

I could not find any piece of code, that would close this resource.

The Statement close() method docs[1] tells us, that it is only a good practice to close the resource manually, with, in this case, stmt.close().

Can you please check, if this finding is reasonable, or not?

[1] https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#close--



 Comments   
Comment by Diego Dupin [ 2022-05-13 ]

Statement close is a good practice, yes.
Statement streaming resultset ( when using setFetchSize) not closed result in having socket still having some data to handle (but connector handle that).
The super mandatory close is when using PreparedStatement with option `useServerPrepStmts` enable. Because if not close PREPARE command is never closed server side until connection close.

In this case, Statement won't do anything on close, so no need to change current implementation. Still good check.

Comment by Zuzana Miklankova [ 2022-05-13 ]

Thank you for checking!

Generated at Thu Feb 08 03:19:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.