You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/10 07:44:32 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #12324: Improve resource release logic to prevent memory leaks.

terrymanu commented on a change in pull request #12324:
URL: https://github.com/apache/shardingsphere/pull/12324#discussion_r705967916



##########
File path: shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandler.java
##########
@@ -56,12 +56,13 @@
     @Override
     public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
         Collection<Grantee> grantees = new LinkedList<>();
-        try (Connection connection = dataSource.getConnection()) {
-            Statement statement = connection.createStatement();
-            try (ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
-                while (resultSet.next()) {
-                    grantees.add(new Grantee(resultSet.getString("user"), resultSet.getString("host")));
-                }
+        try (
+                Connection connection = dataSource.getConnection();
+                Statement statement = connection.createStatement();
+                ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))
+        ) {
+            while (resultSet.next()) {
+                grantees.add(new Grantee(resultSet.getString("user"), resultSet.getString("host")));

Review comment:
       Why the original code may resource leak?
   The connection, statement and resultSet are all in try with resource




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org