aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler
diff options
context:
space:
mode:
authorGravatar Piotr Padlewski <prazek@google.com>2018-08-09 16:24:38 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-09 16:29:06 -0700
commitc38bf1ca5051b15356fe4219f36f7f44829fb2ae (patch)
tree67184c8c1f7cf0e2098371f658f830d8ad1410f9 /tensorflow/compiler
parentb306f5f9458feddbdb89b7db557cb74dc9408d07 (diff)
Fix emplace_back(new) calls
Doing v.emplace_back(new Type) on a std::vector<std::unique_ptr<Type>> is not exception safe. This is because it cause a leak of passed pointer if emplace_back would throw exception before emplacement (e.g. not enough memory to add a new element). PiperOrigin-RevId: 208130121
Diffstat (limited to 'tensorflow/compiler')
-rw-r--r--tensorflow/compiler/xla/service/BUILD1
-rw-r--r--tensorflow/compiler/xla/service/service.cc7
2 files changed, 5 insertions, 3 deletions
diff --git a/tensorflow/compiler/xla/service/BUILD b/tensorflow/compiler/xla/service/BUILD
index 1b93d72a3e..3480ec4038 100644
--- a/tensorflow/compiler/xla/service/BUILD
+++ b/tensorflow/compiler/xla/service/BUILD
@@ -613,6 +613,7 @@ cc_library(
"//tensorflow/compiler/xla:xla_proto",
"//tensorflow/compiler/xla/legacy_flags:debug_options_flags",
"//tensorflow/core:lib",
+ "//tensorflow/core:ptr_util",
"//tensorflow/core:stream_executor_no_cuda",
],
alwayslink = 1,
diff --git a/tensorflow/compiler/xla/service/service.cc b/tensorflow/compiler/xla/service/service.cc
index 433560e322..1dbf540d13 100644
--- a/tensorflow/compiler/xla/service/service.cc
+++ b/tensorflow/compiler/xla/service/service.cc
@@ -53,6 +53,7 @@ limitations under the License.
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/stream_executor_no_cuda.h"
#include "tensorflow/core/platform/types.h"
+#include "tensorflow/core/util/ptr_util.h"
using ::tensorflow::strings::Printf;
using ::tensorflow::strings::StrCat;
@@ -408,7 +409,7 @@ Service::ExecuteParallelAndRegisterResult(
streams.push_back(std::move(stream));
if (replica == 0 && profile != nullptr) {
- timers.emplace_back(new se::Timer(streams.back()->parent()));
+ timers.push_back(MakeUnique<se::Timer>(streams.back()->parent()));
streams.back()
->InitTimer(timers.back().get())
.ThenStartTimer(timers.back().get());
@@ -440,7 +441,7 @@ Service::ExecuteParallelAndRegisterResult(
streams.back()->ThenStopTimer(timers.back().get());
}
- result_buffers.emplace_back(std::move(result));
+ result_buffers.push_back(std::move(result));
}
TF_ASSIGN_OR_RETURN(GlobalDataHandle handle,
allocation_tracker_.RegisterReplicatedBuffers(
@@ -558,7 +559,7 @@ StatusOr<GlobalDataHandle> Service::ExecuteAndRegisterResult(
std::vector<tensorflow::gtl::ArraySlice<const ShapedBuffer*>>
replicated_arguments;
for (const auto& arg : arguments) {
- replicated_arguments.emplace_back(arg);
+ replicated_arguments.push_back(arg);
}
TF_ASSIGN_OR_RETURN(auto results, executable->ExecuteOnStreams(