Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#693] Fix resource leak warnings for org.eclipse.cdt.core.utils #694

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 QNX Software Systems and others.
* Copyright (c) 2000, 2024 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
* Serge Beauchamp - Bug 409916
* John Dallaway - Support DW_FORM_line_strp (#198)
* John Dallaway - Support DW_FORM_implicit_const (#443)
* Alexander Fedorov (ArSysOp) - fix resource leak (#693)
*******************************************************************************/

package org.eclipse.cdt.utils.debug.dwarf;
Expand Down Expand Up @@ -1065,12 +1066,10 @@ void processCompileUnit(IDebugEntryRequestor requestor, List<AttributeValue> lis
}

public static void main(String[] args) {
try {
DebugSymsRequestor symreq = new DebugSymsRequestor();
Dwarf dwarf = new Dwarf(args[0]);
DebugSymsRequestor symreq = new DebugSymsRequestor();
try (Dwarf dwarf = new Dwarf(args[0])) {
dwarf.parse(symreq);
DebugSym[] entries = symreq.getEntries();
for (DebugSym entry : entries) {
for (DebugSym entry : symreq.getEntries()) {
System.out.println(entry);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2024 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,6 +10,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alexander Fedorov (ArSysOp) - fix resource leak (#693)
*******************************************************************************/

package org.eclipse.cdt.utils.debug.tools;
Expand Down Expand Up @@ -48,8 +49,9 @@ void init(Elf elf) throws IOException {
Stabs stabs = new Stabs(elf);
stabs.parse(symreq);
} else if (type == Elf.Attribute.DEBUG_TYPE_DWARF) {
Dwarf dwarf = new Dwarf(elf);
dwarf.parse(symreq);
try (Dwarf dwarf = new Dwarf(elf)) {
dwarf.parse(symreq);
}
} else {
throw new IOException(CCorePlugin.getResourceString("Util.unknownFormat")); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 QNX Software Systems and others.
* Copyright (c) 2000, 2024 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,6 +10,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Alexander Fedorov (ArSysOp) - fix resource leak (#693)
*******************************************************************************/

package org.eclipse.cdt.utils.debug.tools;
Expand Down Expand Up @@ -58,8 +59,9 @@ void parse(Elf elf) throws IOException {
Stabs stabs = new Stabs(elf);
stabs.parse(this);
} else if (type == Elf.Attribute.DEBUG_TYPE_DWARF) {
Dwarf dwarf = new Dwarf(elf);
dwarf.parse(this);
try (Dwarf dwarf = new Dwarf(elf)) {
dwarf.parse(this);
}
} else {
throw new IOException(CCorePlugin.getResourceString("Util.unknownFormat")); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 QNX Software Systems and others.
* Copyright (c) 2000, 2024 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,6 +12,7 @@
* QNX Software Systems - Initial API and implementation
* Craig Watson.
* Apple Computer - work on performance optimizations
* Alexander Fedorov (ArSysOp) - fix resource leak (#693)
*******************************************************************************/
package org.eclipse.cdt.utils.macho;

Expand Down Expand Up @@ -1157,20 +1158,17 @@ public Attribute getAttributes() throws IOException {
}

public static Attribute getAttributes(String file) throws IOException {
MachO64 macho = new MachO64(file);
Attribute attrib = macho.getAttributes();
macho.dispose();
return attrib;
try (MachO64 macho = new MachO64(file)) {
return macho.getAttributes();
}
}

public static Attribute getAttributes(byte[] array) throws IOException {
MachO64 emptyMachO = new MachO64();
emptyMachO.mhdr = emptyMachO.new MachOhdr(array);
//emptyMachO.sections = new MachO64.Section[0];
Attribute attrib = emptyMachO.getAttributes();
emptyMachO.dispose();

return attrib;
try (MachO64 emptyMachO = new MachO64()) {
emptyMachO.mhdr = emptyMachO.new MachOhdr(array);
//emptyMachO.sections = new MachO64.Section[0];
return emptyMachO.getAttributes();
}
}

public static boolean isMachOHeader(byte[] bytes) {
Expand Down