buffet: Fix crash when CommandInstance::SetResults() is invoked
The crash was a result of use-after-delete in
CloudCommandProxy::OnResultsChanged() where TypedValueToJson returned
std::unique_ptr while the JSON value was set to Dictionary by using
unique_ptr::get() on the temporary. Should have called release()
instead to transfer the ownership to the dictionary.
Added a unit test to buffet/device_registration_info_unittest.cc to
test this specific scenario.
BUG=brillo:770
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I34a28ce610a06f2b77af1cc75e358b3fb3562a13
Reviewed-on: https://chromium-review.googlesource.com/264465
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_manager.h b/buffet/commands/command_manager.h
index 8088e26..a703ab3 100644
--- a/buffet/commands/command_manager.h
+++ b/buffet/commands/command_manager.h
@@ -36,6 +36,8 @@
explicit CommandManager(
const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
object_manager);
+ // Special constructor to help mock out command dispatcher for testing.
+ explicit CommandManager(CommandDispachInterface* dispatch_interface);
// Sets callback which is called when command definitions is changed.
void SetOnCommandDefChanged(const base::Closure& on_command_defs_changed) {