@@ -238,9 +238,10 @@ public RSocketStrategies rsocketStrategies() {
238
238
239
239
240
240
/**
241
- * Similar {@link org.springframework.core.io.buffer.LeakAwareDataBufferFactory}
242
- * but extends {@link NettyDataBufferFactory} rather than rely on
243
- * decoration, since {@link PayloadUtils} does instanceof checks.
241
+ * Unlike {@link org.springframework.core.io.buffer.LeakAwareDataBufferFactory}
242
+ * this one is an instance of {@link NettyDataBufferFactory} which is necessary
243
+ * since {@link PayloadUtils} does instanceof checks, and that also allows
244
+ * intercepting {@link NettyDataBufferFactory#wrap(ByteBuf)}.
244
245
*/
245
246
private static class LeakAwareNettyDataBufferFactory extends NettyDataBufferFactory {
246
247
@@ -277,32 +278,33 @@ void reset() {
277
278
278
279
@ Override
279
280
public NettyDataBuffer allocateBuffer () {
280
- return (NettyDataBuffer ) record (super .allocateBuffer ());
281
+ return (NettyDataBuffer ) recordHint (super .allocateBuffer ());
281
282
}
282
283
283
284
@ Override
284
285
public NettyDataBuffer allocateBuffer (int initialCapacity ) {
285
- return (NettyDataBuffer ) record (super .allocateBuffer (initialCapacity ));
286
+ return (NettyDataBuffer ) recordHint (super .allocateBuffer (initialCapacity ));
286
287
}
287
288
288
289
@ Override
289
290
public NettyDataBuffer wrap (ByteBuf byteBuf ) {
290
291
NettyDataBuffer dataBuffer = super .wrap (byteBuf );
291
292
if (byteBuf != Unpooled .EMPTY_BUFFER ) {
292
- record (dataBuffer );
293
+ recordHint (dataBuffer );
293
294
}
294
295
return dataBuffer ;
295
296
}
296
297
297
298
@ Override
298
299
public DataBuffer join (List <? extends DataBuffer > dataBuffers ) {
299
- return record (super .join (dataBuffers ));
300
+ return recordHint (super .join (dataBuffers ));
300
301
}
301
302
302
- private DataBuffer record (DataBuffer buffer ) {
303
- this . created . add ( new DataBufferLeakInfo ( buffer , new AssertionError (String .format (
303
+ private DataBuffer recordHint (DataBuffer buffer ) {
304
+ AssertionError error = new AssertionError (String .format (
304
305
"DataBuffer leak: {%s} {%s} not released.%nStacktrace at buffer creation: " , buffer ,
305
- ObjectUtils .getIdentityHexString (((NettyDataBuffer ) buffer ).getNativeBuffer ())))));
306
+ ObjectUtils .getIdentityHexString (((NettyDataBuffer ) buffer ).getNativeBuffer ())));
307
+ this .created .add (new DataBufferLeakInfo (buffer , error ));
306
308
return buffer ;
307
309
}
308
310
}
0 commit comments