This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new dd54a7a590 HDDS-10204. TypedTable.putWithBatch may leak if conversion
of value throws (#6097)
dd54a7a590 is described below
commit dd54a7a59027a72d7165e10355dd25831b610e0e
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Fri Jan 26 13:46:48 2024 +0100
HDDS-10204. TypedTable.putWithBatch may leak if conversion of value throws
(#6097)
---
.../java/org/apache/hadoop/hdds/utils/db/TypedTable.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
index 8e8abdcc7a..539bf8a29c 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/TypedTable.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Objects;
import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
import org.apache.hadoop.hdds.utils.TableCacheMetrics;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
@@ -165,10 +166,17 @@ public class TypedTable<KEY, VALUE> implements Table<KEY,
VALUE> {
public void putWithBatch(BatchOperation batch, KEY key, VALUE value)
throws IOException {
if (supportCodecBuffer) {
- // The buffers will be released after commit.
- rawTable.putWithBatch(batch,
- keyCodec.toDirectCodecBuffer(key),
- valueCodec.toDirectCodecBuffer(value));
+ CodecBuffer keyBuffer = null;
+ CodecBuffer valueBuffer = null;
+ try {
+ keyBuffer = keyCodec.toDirectCodecBuffer(key);
+ valueBuffer = valueCodec.toDirectCodecBuffer(value);
+ // The buffers will be released after commit.
+ rawTable.putWithBatch(batch, keyBuffer, valueBuffer);
+ } catch (Exception e) {
+ IOUtils.closeQuietly(valueBuffer, keyBuffer);
+ throw e;
+ }
} else {
rawTable.putWithBatch(batch, encodeKey(key), encodeValue(value));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]