This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 3f648ad07d [#6513] fix resource leak in BaseCatalog (#6980)
3f648ad07d is described below
commit 3f648ad07d721b1b932154f85443429282bd4c87
Author: yunchi <[email protected]>
AuthorDate: Sat Apr 26 20:22:42 2025 -0700
[#6513] fix resource leak in BaseCatalog (#6980)
### What changes were proposed in this pull request?
Use a try-with-resources pattern to ensure the `BaseAuthorization`
object is automatically closed when execution exits the try block,
regardless of whether it completes normally or due to an exception.
### Why are the changes needed?
To prevent memory leak.
Fix: #6513
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Existing UTs.
Co-authored-by: Jerry Shao <[email protected]>
---
core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java
b/core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java
index 53005bf9a0..539a19e331 100644
--- a/core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java
+++ b/core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java
@@ -205,9 +205,10 @@ public abstract class BaseCatalog<T extends BaseCatalog>
LOG.info("Authorization provider is not set!");
return;
}
- try {
- BaseAuthorization<?> authorization =
- BaseAuthorization.createAuthorization(classLoader,
authorizationProvider);
+
+ // use try-with-resources to auto-close authorization object if exit
with exception
+ try (BaseAuthorization<?> authorization =
+ BaseAuthorization.createAuthorization(classLoader,
authorizationProvider)) {
authorizationPlugin =
classLoader.withClassLoader(