From 561066c1671e5c23e52e51717ca066efd911fa8a Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 25 Nov 2002 05:55:31 +0000 Subject: [PATCH] new method finalize(). --- .../utils/org/eclipse/cdt/utils/elf/AR.java | 17 +++++++++++++- .../utils/org/eclipse/cdt/utils/elf/Elf.java | 23 +++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java index 29598aad7a0..ba3292099e8 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/AR.java @@ -30,12 +30,27 @@ public class AR { public void dispose() { try { - efile.close(); + if (efile != null) + { + efile.close(); + efile = null; + } } catch( IOException e ) {} } + protected void finalize() throws Throwable { + try + { + dispose(); + } + finally + { + super.finalize(); + } + } + /** * The ARHeader class is used to store the per-object file * archive headers. It can also create an Elf object for inspecting diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index 5328a230f41..f7f7b7c02fb 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -687,15 +687,30 @@ public class Elf { } public void dispose() { - if ( addr2line != null ) { + if (addr2line != null) { addr2line.dispose(); } - if ( cppFilt != null ) { + if (cppFilt != null) { cppFilt.dispose(); } try { - efile.close(); - } catch (IOException e) {} + if (efile != null) { + efile.close(); + efile = null; + } + } catch (IOException e) { + } + } + + /** + * Make sure we do not leak the fds. + */ + protected void finalize() throws Throwable { + try { + dispose(); + } finally { + super.finalize(); + } } public Section[] getSections(int type) throws IOException {