Skip to content

Commit 8ab7a27

Browse files
kevinjzheaux
authored andcommitted
Release ByteBuf
Closes gh-9661
1 parent c8b6dc3 commit 8ab7a27

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

rsocket/src/main/java/org/springframework/security/rsocket/authentication/AuthenticationPayloadExchangeConverter.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,17 +67,23 @@ private Authentication authentication(Map<String, Object> metadata) {
6767
if (authenticationMetadata == null) {
6868
return null;
6969
}
70-
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata);
71-
if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) {
72-
return null;
70+
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer();
71+
try {
72+
rawAuthentication.writeBytes(authenticationMetadata);
73+
if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) {
74+
return null;
75+
}
76+
WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication);
77+
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
78+
return simple(rawAuthentication);
79+
} else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
80+
return bearer(rawAuthentication);
81+
}
82+
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
7383
}
74-
WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication);
75-
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
76-
return simple(rawAuthentication);
77-
} else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
78-
return bearer(rawAuthentication);
84+
finally {
85+
rawAuthentication.release();
7986
}
80-
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
8187
}
8288

8389
private Authentication simple(ByteBuf rawAuthentication) {

0 commit comments

Comments
 (0)