1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 553667 - Resource leak in ElfParser

This change fixes a file descriptor leak in
ElfParser.hasInterpProgramHeader(). An Elf object is created without
calling its Elf.dispose(). This results in a created RandomAccessFile
object, without a respective RandomAccessFile.close() call.

Change-Id: I6d2a0911857eb6fcb388b352801c2259ae19171c
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
This commit is contained in:
Simeon Andreev 2019-12-02 15:21:24 +01:00
parent 51d8fbf666
commit 9d897fcc04

View file

@ -190,10 +190,19 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
try {
/* No PHdr.PT_INTERP found in the hints meaning we need to read the file itself */
return Arrays.stream(new Elf(path.toOSString()).getPHdrs()).anyMatch(phdr -> phdr.p_type == PHdr.PT_INTERP);
return Arrays.stream(getPHdrs(path)).anyMatch(phdr -> phdr.p_type == PHdr.PT_INTERP);
} catch (IOException e) {
CCorePlugin.log(e);
}
return false;
}
private static PHdr[] getPHdrs(IPath path) throws IOException {
Elf elf = new Elf(path.toOSString());
try {
return elf.getPHdrs();
} finally {
elf.dispose();
}
}
}