Skip to content

Commit 32ac31c

Browse files
kevinjzheaux
kevin
authored andcommitted
Release ByteBuf
Closes gh-9661
1 parent cb6e4f4 commit 32ac31c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

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

+17-11
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.
@@ -71,18 +71,24 @@ private Authentication authentication(Map<String, Object> metadata) {
7171
if (authenticationMetadata == null) {
7272
return null;
7373
}
74-
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata);
75-
if (!AuthMetadataCodec.isWellKnownAuthType(rawAuthentication)) {
76-
return null;
77-
}
78-
WellKnownAuthType wellKnownAuthType = AuthMetadataCodec.readWellKnownAuthType(rawAuthentication);
79-
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
80-
return simple(rawAuthentication);
74+
ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer();
75+
try {
76+
rawAuthentication.writeBytes(authenticationMetadata);
77+
if (!AuthMetadataCodec.isWellKnownAuthType(rawAuthentication)) {
78+
return null;
79+
}
80+
WellKnownAuthType wellKnownAuthType = AuthMetadataCodec.readWellKnownAuthType(rawAuthentication);
81+
if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) {
82+
return simple(rawAuthentication);
83+
}
84+
if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
85+
return bearer(rawAuthentication);
86+
}
87+
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
8188
}
82-
if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) {
83-
return bearer(rawAuthentication);
89+
finally {
90+
rawAuthentication.release();
8491
}
85-
throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType);
8692
}
8793

8894
private Authentication simple(ByteBuf rawAuthentication) {

0 commit comments

Comments
 (0)