summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUtkarsh Sanghi <usanghi@google.com>2015-11-24 08:48:31 -0800
committerUtkarsh Sanghi <usanghi@google.com>2015-11-24 08:48:31 -0800
commitd1423101f0dced3e428ff365bcf2e87aac1b575e (patch)
tree5d1d49dab84a7951a622d0e466b0b59d380a19bc
parente4bbdae528c3b48c8001967ff04cb7767f15db98 (diff)
downloadtpm-d1423101f0dced3e428ff365bcf2e87aac1b575e.tar.gz
trunks: Do not re-initialize DBus bus.
Before this CL, trunks_proxy reinitializes the DBus bus on every new thread it is called. This can lead to memory leaks, and since trunks hold tpm communication state, it results in errors when called in multiple threads. This CL enfores the requriment that trunks_proxy must be intialized and called on the same thread. BUG=None TEST=call trunks calls in two threads and observe errors. Change-Id: I52b714f5c3563bebf6632718a1ef29ef3f7fc0bc
-rw-r--r--trunks/trunks_proxy.cc10
-rw-r--r--trunks/trunks_proxy.h3
2 files changed, 6 insertions, 7 deletions
diff --git a/trunks/trunks_proxy.cc b/trunks/trunks_proxy.cc
index a37e006..2ab4774 100644
--- a/trunks/trunks_proxy.cc
+++ b/trunks/trunks_proxy.cc
@@ -57,9 +57,8 @@ bool TrunksProxy::Init() {
void TrunksProxy::SendCommand(const std::string& command,
const ResponseCallback& callback) {
- if ((origin_thread_id_ != base::PlatformThread::CurrentId()) &&
- (!Init())) {
- LOG(ERROR) << "Error intializing trunks dbus proxy object.";
+ if (origin_thread_id_ != base::PlatformThread::CurrentId()) {
+ LOG(ERROR) << "Error TrunksProxy cannot be shared by multiple threads.";
callback.Run(CreateErrorResponse(TRUNKS_RC_IPC_ERROR));
}
SendCommandRequest tpm_command_proto;
@@ -80,9 +79,8 @@ void TrunksProxy::SendCommand(const std::string& command,
}
std::string TrunksProxy::SendCommandAndWait(const std::string& command) {
- if ((origin_thread_id_ != base::PlatformThread::CurrentId()) &&
- (!Init())) {
- LOG(ERROR) << "Error intializing trunks dbus proxy object.";
+ if (origin_thread_id_ != base::PlatformThread::CurrentId()) {
+ LOG(ERROR) << "Error TrunksProxy cannot be shared by multiple threads.";
return CreateErrorResponse(TRUNKS_RC_IPC_ERROR);
}
SendCommandRequest tpm_command_proto;
diff --git a/trunks/trunks_proxy.h b/trunks/trunks_proxy.h
index 1951e0e..858b1ea 100644
--- a/trunks/trunks_proxy.h
+++ b/trunks/trunks_proxy.h
@@ -32,7 +32,8 @@ namespace trunks {
// TrunksProxy is a CommandTransceiver implementation that forwards all commands
// to the trunksd D-Bus daemon. See TrunksService for details on how the
-// commands are handled once they reach trunksd.
+// commands are handled once they reach trunksd. TrunksProxy must be used in
+// only one thread.
class TRUNKS_EXPORT TrunksProxy: public CommandTransceiver {
public:
TrunksProxy();