Release ByteBuf

Closes gh-9661
This commit is contained in:
kevin 2021-04-22 09:29:04 +08:00 committed by Josh Cummings
parent c8b6dc390d
commit 8ab7a27a20
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
1 changed files with 16 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019 the original author or authors.
* Copyright 2019-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -67,17 +67,23 @@ public class AuthenticationPayloadExchangeConverter implements PayloadExchangeAu
if (authenticationMetadata == null) {
return null;
}
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata);
if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) {
return null;
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer();
try {
rawAuthentication.writeBytes(authenticationMetadata);
if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) {
return null;
}
WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication);
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
return simple(rawAuthentication);
} else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
return bearer(rawAuthentication);
}
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
}
WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication);
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
return simple(rawAuthentication);
} else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
return bearer(rawAuthentication);
finally {
rawAuthentication.release();
}
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
}
private Authentication simple(ByteBuf rawAuthentication) {