Fix bugs in AssignOp:
authorA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 30 Apr 2018 19:01:35 +0000 (12:01 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Mon, 30 Apr 2018 19:04:15 +0000 (12:04 -0700)
 1. Releasing the unique_ptr would "leak" a TensorBuffer refcount.
 2. The output shape is defined by rhs, not lhs.

PiperOrigin-RevId: 194822802

tensorflow/core/kernels/assign_op.h

index 2ed1628..19b38f9 100644 (file)
@@ -78,11 +78,10 @@ class AssignOp : public OpKernel {
       // 1. Try to reuse the rhs.
       std::unique_ptr<Tensor> input_alias = context->forward_input(
           1, OpKernelContext::Params::kNoReservation /*output_index*/,
-          old_lhs.dtype(), old_lhs.shape(), DEVICE_MEMORY, attr);
+          rhs.dtype(), rhs.shape(), DEVICE_MEMORY, attr);
       if (input_alias != nullptr) {
         // Transfer ownership to the ref.
-        context->replace_ref_input(0, *input_alias.release(),
-                                   /* lock_held */ true);
+        context->replace_ref_input(0, *input_alias, /* lock_held */ true);
         return;
       }