From 9c1e98dac54ed2ce169f3f3df05bc80052f6a217 Mon Sep 17 00:00:00 2001 From: Calvin Cheung Date: Wed, 11 Jan 2023 17:48:36 +0000 Subject: [PATCH] 8298321: 2 File Leak defect groups in 2 files Reviewed-by: vlivanov, iklam, dholmes --- src/hotspot/os/posix/perfMemory_posix.cpp | 5 ++++- src/hotspot/share/compiler/directivesParser.cpp | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/posix/perfMemory_posix.cpp b/src/hotspot/os/posix/perfMemory_posix.cpp index c4cdb4c74f5..598955cbdfb 100644 --- a/src/hotspot/os/posix/perfMemory_posix.cpp +++ b/src/hotspot/os/posix/perfMemory_posix.cpp @@ -1205,7 +1205,10 @@ static void mmap_attach_shared(int vmid, char** addr, size_t* sizep, TRAPS) { FREE_C_HEAP_ARRAY(char, dirname); FREE_C_HEAP_ARRAY(char, filename); - if (fd == OS_ERR || HAS_PENDING_EXCEPTION) { + if (HAS_PENDING_EXCEPTION) { + assert(fd == OS_ERR, "open_sharedmem_file always return OS_ERR on exceptions"); + } + if (fd == OS_ERR) { return; } diff --git a/src/hotspot/share/compiler/directivesParser.cpp b/src/hotspot/share/compiler/directivesParser.cpp index e48ac58b31c..edb7a3af918 100644 --- a/src/hotspot/share/compiler/directivesParser.cpp +++ b/src/hotspot/share/compiler/directivesParser.cpp @@ -96,10 +96,9 @@ bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* // read contents into resource array char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1); ssize_t num_read = ::read(file_handle, (char*) buffer, st.st_size); + ::close(file_handle); if (num_read >= 0) { buffer[num_read] = '\0'; - // close file - ::close(file_handle); return parse_string(buffer, stream) > 0; } }