From fe7fca0128ca3a7b514c49d1508ca64499a8bb8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jeli=C5=84ski?= Date: Mon, 16 Jan 2023 06:56:43 +0000 Subject: [PATCH] 8300032: DwarfParser resource leak Reviewed-by: cjplummer, sspitsyn --- .../jvm/hotspot/debugger/linux/amd64/DwarfParser.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/DwarfParser.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/DwarfParser.java index 5b7e1166e2b..3b63ee0a21e 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/DwarfParser.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/DwarfParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, NTT DATA. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -30,6 +30,7 @@ import sun.jvm.hotspot.debugger.Address; import sun.jvm.hotspot.debugger.DebuggerException; public class DwarfParser { + private static final Cleaner CLEANER = Cleaner.create(); private final long p_dwarf_context; // native dwarf context handle private static native void init0(); @@ -41,6 +42,10 @@ public class DwarfParser { init0(); } + private static Runnable cleanerFor(long context) { + return () -> DwarfParser.destroyDwarfContext(context); + } + public DwarfParser(Address lib) { p_dwarf_context = createDwarfContext(lib.asLongValue()); @@ -48,8 +53,7 @@ public class DwarfParser { throw new DebuggerException("Could not create DWARF context"); } - Cleaner.create() - .register(this, () -> DwarfParser.destroyDwarfContext(p_dwarf_context)); + CLEANER.register(this, cleanerFor(p_dwarf_context)); } public boolean isIn(Address pc) {