From 693aa38472d90f55d2efd7807052c527032513a6 Mon Sep 17 00:00:00 2001 From: Viktor Gal Date: Sat, 16 Mar 2019 07:40:59 +0100 Subject: [PATCH] Check whether the file descriptor is valid calling PosixWritableFile::Close twice should not cause segfaults --- tensorflow/core/platform/posix/posix_file_system.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tensorflow/core/platform/posix/posix_file_system.cc b/tensorflow/core/platform/posix/posix_file_system.cc index 083284c5ff9..db54ded8a83 100644 --- a/tensorflow/core/platform/posix/posix_file_system.cc +++ b/tensorflow/core/platform/posix/posix_file_system.cc @@ -105,6 +105,9 @@ class PosixWritableFile : public WritableFile { } Status Close() override { + if (file_ == nullptr) { + return IOError(filename_, EBADF); + } Status result; if (fclose(file_) != 0) { result = IOError(filename_, errno);