Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several potential memory leaks #14816

Merged
merged 5 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorflow/c/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ TF_Tensor* TF_TensorFromTensor(const tensorflow::Tensor& src,
status->status = InvalidArgument(
"invalid string tensor encoding (string #", i, " of ",
srcarray.size(), "): ", status->status.error_message());
delete[] base;
return nullptr;
}
dst += consumed;
Expand All @@ -589,6 +590,7 @@ TF_Tensor* TF_TensorFromTensor(const tensorflow::Tensor& src,
status->status = InvalidArgument(
"invalid string tensor encoding (decoded ", (dst - base),
" bytes, but the tensor is encoded in ", size, " bytes");
delete[] base;
return nullptr;
}

Expand Down
3 changes: 1 addition & 2 deletions tensorflow/core/lib/io/snappy/snappy_outputbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Status SnappyOutputBuffer::Deflate() {
}

// Write length of compressed block to output buffer.
char* compressed_length_array = new char[4];
char compressed_length_array[4];
std::fill(compressed_length_array, compressed_length_array + 4, 0);
for (int i = 0; i < 4; i++) {
// Little endian.
Expand All @@ -173,7 +173,6 @@ Status SnappyOutputBuffer::Deflate() {
TF_RETURN_IF_ERROR(AddToOutputBuffer(output.data(), output.size()));
next_in_ += avail_in_;
avail_in_ = 0;
delete[] compressed_length_array;

return Status::OK();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ int64 AndroidArmV7ACpuUtilsHelper::ReadCpuFrequencyFile(
const int retval = fscanf(fp, "%lld", &freq_in_khz);
if (retval < 0) {
LOG(WARNING) << "Failed to \"" << file_path << "\"";
fclose(fp);
return INVALID_CPU_FREQUENCY;
}
pclose(fp);
fclose(fp);
return freq_in_khz * 1000; // The file contains cpu frequency in khz
}

Expand Down
1 change: 1 addition & 0 deletions tensorflow/tools/proto_text/gen_proto_text_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int MainImpl(int argc, char** argv) {
FILE* f = fopen(path.c_str(), "w");
if (f == nullptr) return -1;
if (fwrite(data.c_str(), 1, data.size(), f) != data.size()) {
fclose(f);
return -1;
}
if (fclose(f) != 0) {
Expand Down