Skip to content

Commit 0aa75e6

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Fix EValue construction from a smart pointer. (#5357)
Summary: Pull Request resolved: #5357 The move constructor invoked by `*this =` expression tries to `destroy()` the `this` first, but it's not yet initialized. For example, if the tag is randomly `Tag::ListTensor`, `destroy()` will try to iterate over and destroy a list of tensors. But since the memory is uninitialized, it will typically crash or corrupt memory. Reviewed By: dbort Differential Revision: D62658327 fbshipit-source-id: a12cb48f4bc3384a80534a453909e010c9549850
1 parent 69d33a8 commit 0aa75e6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

runtime/core/evalue.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ struct EValue {
248248
decltype(*std::forward<T>(value)),
249249
EValue>::value>::type* = 0) {
250250
ET_CHECK_MSG(value != nullptr, "Pointer is null.");
251-
*this = EValue(*std::forward<T>(value));
251+
// Note that this ctor does not initialize this->tag directly; it is set by
252+
// moving in the new value.
253+
moveFrom(*std::forward<T>(value));
252254
}
253255

254256
// Delete constructor for raw pointers to ensure they cannot be used.

0 commit comments

Comments
 (0)