Skip to content

Fix JDBC resource leaks in JdbcCatalog and JdbcUtil#15463

Open
PDGGK wants to merge 1 commit intoapache:mainfrom
PDGGK:fix-jdbc-resource-leaks
Open

Fix JDBC resource leaks in JdbcCatalog and JdbcUtil#15463
PDGGK wants to merge 1 commit intoapache:mainfrom
PDGGK:fix-jdbc-resource-leaks

Conversation

@PDGGK
Copy link

@PDGGK PDGGK commented Feb 27, 2026

Description

Fixes 4 JDBC resource leaks in JdbcCatalog and JdbcUtil by replacing manual resource management with try-with-resources.

Closes #15462

Changes

JdbcUtil.javatableOrView()

  • Wrap ResultSet rs = sql.executeQuery() in try-with-resources. Previously a manual rs.close() existed but was skipped on exceptions, leaking the ResultSet.

JdbcCatalog.javaatomicCreateTable()

  • Wrap dbMeta.getTables() ResultSet in try-with-resources (was never closed).
  • Wrap conn.prepareStatement(sqlCommand) in try-with-resources (inline statement was never closed).

JdbcCatalog.javaupdateSchemaIfRequired()

  • Wrap dbMeta.getColumns() ResultSet in try-with-resources (was never closed on either branch).
  • Wrap conn.prepareStatement(V1_UPDATE_CATALOG_SQL) in try-with-resources (inline statement was never closed).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Code follows the project's code style
  • Self-review of the code completed
  • No new tests required (pure resource management fix, logic unchanged)

Use try-with-resources for ResultSet and PreparedStatement objects
in JdbcUtil.tableOrView(), JdbcCatalog.atomicCreateTable(), and
JdbcCatalog.updateSchemaIfRequired() to ensure they are always
closed even when exceptions occur.

Closes apache#15462
@github-actions github-actions bot added the core label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JDBC resource leaks in JdbcCatalog and JdbcUtil: ResultSet and PreparedStatement not closed

1 participant