Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1946)

Unified Diff: mojo/spy/spy.cc

Issue 233073005: Mojo Spy: Fix a couple of bugs noticed by vtl@ and qsr@ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/spy/spy.cc
diff --git a/mojo/spy/spy.cc b/mojo/spy/spy.cc
index 0a4b75a6f3c2c855ef31f333e8b61bf7dc73009c..d29cea5417ea76040c582e1793c6e9084a09fa3d 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -18,6 +18,11 @@ namespace {
const size_t kMessageBufSize = 2 * 1024;
const size_t kHandleBufSize = 64;
+void CloseHandles(MojoHandle* handles, size_t count) {
+ for (size_t ix = 0; ix != count; ++count)
+ MojoClose(handles[ix]);
+}
+
// In charge of processing messages that flow over a
// single message pipe.
class MessageProcessor :
@@ -43,8 +48,8 @@ class MessageProcessor :
wait_flags.push_back(MOJO_WAIT_FLAG_READABLE);
wait_flags.push_back(MOJO_WAIT_FLAG_READABLE);
- scoped_ptr<char> mbuf(new char[kMessageBufSize]);
- scoped_ptr<MojoHandle> hbuf(new MojoHandle[kHandleBufSize]);
+ scoped_ptr<char[]> mbuf(new char[kMessageBufSize]);
+ scoped_ptr<MojoHandle[]> hbuf(new MojoHandle[kHandleBufSize]);
// Main processing loop:
// 1- Wait for an endpoint to have a message.
@@ -87,10 +92,13 @@ class MessageProcessor :
if (!CheckResult(WriteMessageRaw(write_handle,
mbuf.get(), bytes_read,
hbuf.get(), handles_read,
- MOJO_WRITE_MESSAGE_FLAG_NONE)))
+ MOJO_WRITE_MESSAGE_FLAG_NONE))) {
+ // On failure we own the handles. For now just close them.
+ if (handles_read)
+ CloseHandles(hbuf.get(), handles_read);
break;
+ }
}
-
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698