FdFile needs close even without any valid FD
The FdFile struct requires that Flush and Close be called even if
there is no fd associated with the struct. This meant that test 1963
would fail a DCHECK if memfd_create fails.
Test: Modify libartbase/base/memfd.cc to always fail.
./test/run-test --host 1963
Bug: 133731001
Change-Id: I34d2949f43d7943a3a900b0b641eb7a3525352d4
diff --git a/openjdkjvmti/ti_search.cc b/openjdkjvmti/ti_search.cc
index 5654c22..f4c3a2d 100644
--- a/openjdkjvmti/ti_search.cc
+++ b/openjdkjvmti/ti_search.cc
@@ -288,11 +288,17 @@
if (file.Fd() < 0) {
char* reason = strerror(errno);
JVMTI_LOG(ERROR, jvmti_env) << "Unable to create memfd due to " << reason;
+ if (file.FlushClose() < 0) {
+ PLOG(WARNING) << "Failed to close file!";
+ }
return ERR(INTERNAL);
}
// Fill it with the buffer.
if (!file.WriteFully(dex_bytes, dex_bytes_length) || file.Flush() != 0) {
JVMTI_LOG(ERROR, jvmti_env) << "Failed to write to memfd!";
+ if (file.FlushClose() < 0) {
+ PLOG(WARNING) << "Failed to close file!";
+ }
return ERR(INTERNAL);
}
// Get the filename in procfs.