Check data buffer before release()
@@ -386,9 +386,8 @@ public class MessageCrypto {
keyInfo.getMetadata().forEach((key, value) -> {
kvList.add(KeyValue.newBuilder().setKey(key).setValue(value).build());
});
- msgMetadata.addEncryptionKeys(
- EncryptionKeys.newBuilder().setKey(keyName).setValue(ByteString.copyFrom(keyInfo.getKey()))
- .addAllMetadata(kvList).build());
+ msgMetadata.addEncryptionKeys(EncryptionKeys.newBuilder().setKey(keyName)
+ .setValue(ByteString.copyFrom(keyInfo.getKey())).addAllMetadata(kvList).build());
} else {
msgMetadata.addEncryptionKeys(EncryptionKeys.newBuilder().setKey(keyName)
.setValue(ByteString.copyFrom(keyInfo.getKey())).build());
@@ -512,9 +511,11 @@ public class MessageCrypto {
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException
| BadPaddingException | ShortBufferException e) {
+ log.error("{} Failed to decrypt message {}", logCtx, e.getMessage());
+ if (targetBuf != null) {
targetBuf.release();
targetBuf = null;
- log.error("{} Failed to decrypt message {}", logCtx, e.getMessage());
+ }
}
return targetBuf;
