File tree 6 files changed +39
-12
lines changed
java/ca/fxco/memoryleakfix
6 files changed +39
-12
lines changed Original file line number Diff line number Diff line change 1
1
package ca .fxco .memoryleakfix ;
2
2
3
- import io .netty .buffer .ByteBuf ;
4
3
import net .fabricmc .api .ModInitializer ;
5
4
import net .fabricmc .loader .api .FabricLoader ;
6
5
6
+ import net .minecraft .network .PacketByteBuf ;
7
7
import org .spongepowered .asm .logging .ILogger ;
8
8
import org .spongepowered .asm .logging .LoggerAdapterDefault ;
9
9
import org .spongepowered .asm .mixin .MixinEnvironment ;
15
15
16
16
public class MemoryLeakFix implements ModInitializer {
17
17
18
- public static final Set <ByteBuf > BUFFERS_TO_CLEAR = Collections .synchronizedSet (new HashSet <>());
18
+ public static final Set <PacketByteBuf > BUFFERS_TO_CLEAR = Collections .synchronizedSet (new HashSet <>());
19
19
20
20
@ Override
21
21
public void onInitialize () {}
Original file line number Diff line number Diff line change
1
+ package ca .fxco .memoryleakfix .extensions ;
2
+
3
+ public interface ExtendPacketByteBuf {
4
+ boolean isAccessible ();
5
+ }
Original file line number Diff line number Diff line change 1
1
package ca .fxco .memoryleakfix .mixin .accessor ;
2
2
3
- import io .netty .buffer .AbstractReferenceCountedByteBuf ;
3
+ import io .netty .buffer .ByteBuf ;
4
4
import org .spongepowered .asm .mixin .Mixin ;
5
5
import org .spongepowered .asm .mixin .gen .Invoker ;
6
6
7
- @ Mixin (AbstractReferenceCountedByteBuf .class )
8
- public interface AbstractReferenceCountedByteBufAccessor {
7
+ @ Mixin (ByteBuf .class )
8
+ public interface ByteBufAccessor {
9
9
@ Invoker ("isAccessible" )
10
10
boolean invokeIsAccessible ();
11
11
}
Original file line number Diff line number Diff line change 1
1
package ca .fxco .memoryleakfix .mixin .customPayloadLeak ;
2
2
3
3
import ca .fxco .memoryleakfix .MemoryLeakFix ;
4
- import ca .fxco .memoryleakfix .mixin .accessor .AbstractReferenceCountedByteBufAccessor ;
5
- import io .netty .buffer .ByteBuf ;
4
+ import ca .fxco .memoryleakfix .extensions .ExtendPacketByteBuf ;
6
5
import net .fabricmc .api .EnvType ;
7
6
import net .fabricmc .api .Environment ;
8
7
import net .minecraft .client .MinecraftClient ;
8
+ import net .minecraft .network .PacketByteBuf ;
9
9
import org .spongepowered .asm .mixin .Mixin ;
10
10
import org .spongepowered .asm .mixin .injection .At ;
11
11
import org .spongepowered .asm .mixin .injection .Inject ;
@@ -20,10 +20,8 @@ public class MinecraftClient_freeBufferMixin {
20
20
*/
21
21
22
22
// Make sure that the there is a reference to release first!
23
- private boolean tryRelease (ByteBuf buffer ) {
24
- return buffer .refCnt () == 0 &&
25
- ((AbstractReferenceCountedByteBufAccessor )buffer ).invokeIsAccessible () &&
26
- buffer .release ();
23
+ private boolean tryRelease (PacketByteBuf buffer ) {
24
+ return ((ExtendPacketByteBuf )buffer ).isAccessible () && buffer .release ();
27
25
}
28
26
29
27
Original file line number Diff line number Diff line change
1
+ package ca .fxco .memoryleakfix .mixin .customPayloadLeak ;
2
+
3
+ import ca .fxco .memoryleakfix .extensions .ExtendPacketByteBuf ;
4
+ import ca .fxco .memoryleakfix .mixin .accessor .ByteBufAccessor ;
5
+ import io .netty .buffer .ByteBuf ;
6
+ import net .minecraft .network .PacketByteBuf ;
7
+ import org .spongepowered .asm .mixin .Final ;
8
+ import org .spongepowered .asm .mixin .Mixin ;
9
+ import org .spongepowered .asm .mixin .Shadow ;
10
+
11
+ @ Mixin (PacketByteBuf .class )
12
+ public class PacketByteBuf_extendMixin implements ExtendPacketByteBuf {
13
+
14
+ @ Shadow
15
+ @ Final
16
+ private ByteBuf parent ;
17
+
18
+
19
+ @ Override
20
+ public boolean isAccessible () {
21
+ return ((ByteBufAccessor )this .parent ).invokeIsAccessible ();
22
+ }
23
+ }
Original file line number Diff line number Diff line change 7
7
" spongePoweredLeak.MinecraftServer_loadWorldMixin"
8
8
],
9
9
"client" : [
10
- " accessor.AbstractReferenceCountedByteBufAccessor " ,
10
+ " accessor.ByteBufAccessor " ,
11
11
" customPayloadLeak.CustomPayloadS2CPacket_bufferMixin" ,
12
12
" customPayloadLeak.MinecraftClient_freeBufferMixin" ,
13
+ " customPayloadLeak.PacketByteBuf_extendMixin" ,
13
14
" hugeScreenshotLeak.MinecraftClient_screenshotMixin" ,
14
15
" readResourcesLeak.TextureUtil_freeBufferMixin" ,
15
16
" spongePoweredLeak.Main_clientLoadedMixin" ,
You can’t perform that action at this time.
0 commit comments