Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-12836

Resource leaks in EntitySQLProcessor.groovy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • webtools
    • None

    Description

      In framework/webtools/groovyScripts/entity/EntitySQLProcessor.groovy at line 35 https://github.com/apache/ofbiz-framework/blob/e080f0bfa657b8b6ffd4cbf5629e0c648440b5f0/framework/webtools/groovyScripts/entity/EntitySQLProcessor.groovy#L35
       
      it creates an SQLProcessor. SQLProcessor has a Close method and implements AutoCloseable, but we're not using try-with-resources, nor directly calling the Close method.
       
      Similarly,
       
      https://github.com/apache/ofbiz-framework/blob/e080f0bfa657b8b6ffd4cbf5629e0c648440b5f0/framework/webtools/groovyScripts/entity/EntitySQLProcessor.groovy#L38
       
      obtains a java.sql.Resultset, which will be closed when everything works, but would leak if there was an exception. Again, we should be using try-with-resources.
       
      Note that according to
       
      https://docs.oracle.com/en/java/javase/20/docs/api/java.sql/java/sql/ResultSet.html#close()
       
      "Calling the method close on a ResultSet object that is already closed is a no-op.", if you obtain a ResultSet from the SQLProcessor and directly close that ResultSet, it's not a problem when the SQLProcessor.close also attempts to close the ResultSet.
       
      The problem is minor, most of the time. The groovy script is in the webtools, so used for developer tinkering and not production use.
       
      When you're doing a SELECT, the script is closing the ResultSet, so the important resources are cleaned up (assuming no exception occurred).
       
      However, if you are doing INSERT, UPDATE or DELETE, the script creates a prepared statement that is not closed, so there's a resource leak.

      Attachments

        1. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy-5.patch
          4 kB
          Paul Foxworthy
        2. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy-4.patch
          4 kB
          Paul Foxworthy
        3. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy-3.patch
          4 kB
          Paul Foxworthy
        4. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy-2.patch
          4 kB
          Paul Foxworthy
        5. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy-1.patch
          4 kB
          Paul Foxworthy
        6. Fixed__Resource_leaks_in_EntitySQLProcessor_groovy.patch
          4 kB
          Paul Foxworthy
        7. EntitySQLProcessor-4.groovy
          3 kB
          Paul Foxworthy
        8. EntitySQLProcessor-3.groovy
          3 kB
          Paul Foxworthy
        9. EntitySQLProcessor-2.groovy
          3 kB
          Paul Foxworthy
        10. EntitySQLProcessor-1.groovy
          3 kB
          Paul Foxworthy
        11. EntitySQLProcessor.groovy
          3 kB
          Paul Foxworthy

        Activity

          People

            paulfoxworthy Paul Foxworthy
            paulfoxworthy Paul Foxworthy
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: