[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request tensorflow#37749 from t-ubukata:bug-error-check
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 316929300
Change-Id: I39196dc247da04fbec47f30123ca10d0c8cc4613
  • Loading branch information
tensorflower-gardener committed Jun 17, 2020
2 parents c6a3ab1 + fea3433 commit 587ff8b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
8 changes: 6 additions & 2 deletions tensorflow/core/platform/cloud/curl_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ CurlHttpRequest::~CurlHttpRequest() {
libcurl_->curl_slist_free_all(resolve_list_);
}
if (put_body_) {
fclose(put_body_);
if (fclose(put_body_) != 0) {
LOG(ERROR) << "fclose() failed: " << strerror(errno);
}
}
if (curl_) {
libcurl_->curl_easy_cleanup(curl_);
Expand Down Expand Up @@ -239,7 +241,9 @@ Status CurlHttpRequest::SetPutFromFile(const string& body_filepath,
is_method_set_ = true;
method_ = RequestMethod::kPut;
if (put_body_) {
fclose(put_body_);
if (fclose(put_body_) != 0) {
LOG(ERROR) << "fclose() failed: " << strerror(errno);
}
}
put_body_ = fopen(body_filepath.c_str(), "r");
if (!put_body_) {
Expand Down
14 changes: 11 additions & 3 deletions tensorflow/core/platform/default/posix_file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class PosixRandomAccessFile : public RandomAccessFile {
public:
PosixRandomAccessFile(const string& fname, int fd)
: filename_(fname), fd_(fd) {}
~PosixRandomAccessFile() override { close(fd_); }
~PosixRandomAccessFile() override {
if (close(fd_) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
}

Status Name(StringPiece* result) const override {
*result = filename_;
Expand Down Expand Up @@ -229,7 +233,9 @@ Status PosixFileSystem::NewReadOnlyMemoryRegionFromFile(
} else {
result->reset(new PosixReadOnlyMemoryRegion(address, st.st_size));
}
close(fd);
if (close(fd) < 0) {
s = IOError(fname, errno);
}
}
return s;
}
Expand All @@ -256,7 +262,9 @@ Status PosixFileSystem::GetChildren(const string& dir,
result->push_back(entry->d_name);
}
}
closedir(d);
if (closedir(d) < 0) {
return IOError(dir, errno);
}
return Status::OK();
}

Expand Down
36 changes: 27 additions & 9 deletions tensorflow/core/platform/default/subprocess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ void SubProcess::FreeArgs() {
void SubProcess::ClosePipes() {
for (int i = 0; i < kNFds; i++) {
if (parent_pipe_[i] >= 0) {
close(parent_pipe_[i]);
if (close(parent_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
parent_pipe_[i] = -1;
}
if (child_pipe_[i] >= 0) {
close(child_pipe_[i]);
if (close(child_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
child_pipe_[i] = -1;
}
}
Expand Down Expand Up @@ -215,7 +219,9 @@ bool SubProcess::Start() {
running_ = true;
for (int i = 0; i < kNFds; i++) {
if (child_pipe_[i] >= 0) {
close(child_pipe_[i]);
if (close(child_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
child_pipe_[i] = -1;
}
}
Expand All @@ -227,7 +233,9 @@ bool SubProcess::Start() {
int devnull_fd = -1;
for (int i = 0; i < kNFds; i++) {
if (parent_pipe_[i] >= 0) {
close(parent_pipe_[i]);
if (close(parent_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
parent_pipe_[i] = -1;
}

Expand All @@ -242,7 +250,9 @@ bool SubProcess::Start() {
_exit(1);
}
}
close(child_pipe_[i]);
if (close(child_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
child_pipe_[i] = -1;
break;

Expand All @@ -264,14 +274,18 @@ bool SubProcess::Start() {
}
}
} else {
close(i);
if (close(i) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
}
break;
}
}

if (devnull_fd >= 0) {
close(devnull_fd);
if (close(devnull_fd) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
}

// Execute the child program.
Expand Down Expand Up @@ -379,7 +393,9 @@ int SubProcess::Communicate(const string* stdin_input, string* stdout_output,
// Special case: if no data is given to send to the child process,
// close the pipe to unblock the child, and skip the file descriptor.
if (stdin_input == nullptr) {
close(parent_pipe_[i]);
if (close(parent_pipe_[i]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
parent_pipe_[i] = -1;
continue;
}
Expand Down Expand Up @@ -441,7 +457,9 @@ int SubProcess::Communicate(const string* stdin_input, string* stdout_output,
fds[i].fd = -1;
fd_remain--;
// Close the child's stdin pipe to unblock the process.
close(parent_pipe_[CHAN_STDIN]);
if (close(parent_pipe_[CHAN_STDIN]) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
parent_pipe_[CHAN_STDIN] = -1;
}
} else if (!retry(errno)) {
Expand Down
4 changes: 3 additions & 1 deletion tensorflow/core/platform/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ string GetTempFilename(const string& extension) {
if (fd < 0) {
LOG(FATAL) << "Failed to create temp file.";
} else {
close(fd);
if (close(fd) < 0) {
LOG(ERROR) << "close() failed: " << strerror(errno);
}
return tmp_filepath;
}
}
Expand Down
4 changes: 3 additions & 1 deletion tensorflow/core/platform/platform_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ int GetPlatformStrings(const std::string& path,
}

result = (ferror(ifp) == 0) ? 0 : errno;
fclose(ifp);
if (fclose(ifp) != 0) {
result = errno;
}
} else {
result = errno;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ int64 AndroidArmV7ACpuUtilsHelper::ReadCpuFrequencyFile(
const int retval = fscanf(fp, "%" SCNd64, &freq_in_khz);
if (retval < 0) {
LOG(WARNING) << "Failed to \"" << file_path << "\"";
fclose(fp);
if (fclose(fp) != 0) {
LOG(WARNING) << "fclose() failed: " << strerror(errno);
}
return INVALID_CPU_FREQUENCY;
}
fclose(fp);
if (fclose(fp) != 0) {
LOG(WARNING) << "fclose() failed: " << strerror(errno);
}
return freq_in_khz * 1000; // The file contains cpu frequency in khz
}

Expand Down

0 comments on commit 587ff8b

Please sign in to comment.