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

Unified Diff: runtime/bin/socket_impl.dart

Issue 8659032: Fix memory leak in MacOS process handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month 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 | « runtime/bin/socket.dart ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_impl.dart
diff --git a/runtime/bin/socket_impl.dart b/runtime/bin/socket_impl.dart
index 9cc1a1a5bbfadccc209624b4fa2452693f1beffd..b797d7de82464dbc7991557145aea80fe5dcde2e 100644
--- a/runtime/bin/socket_impl.dart
+++ b/runtime/bin/socket_impl.dart
@@ -298,7 +298,7 @@ class _Socket extends _SocketBase implements Socket {
}
int result = _readList(buffer, offset, bytes);
if (result < 0) {
- throw new SocketIOException("Error: readList failed");
+ _reportError();
}
return result;
}
@@ -323,7 +323,14 @@ class _Socket extends _SocketBase implements Socket {
if ((offset + bytes) > buffer.length) {
throw new IndexOutOfRangeException(offset + bytes);
}
- return _writeList(buffer, offset, bytes);
+ var bytes_written = _writeList(buffer, offset, bytes);
+ if (bytes_written < 0) {
+ // If writing fails we return 0 as the number of bytes and
+ // report the error on the error handler.
+ bytes_written = 0;
+ _reportError();
+ }
+ return bytes_written;
}
throw new
SocketIOException("Error: writeList failed - invalid socket handle");
@@ -332,6 +339,17 @@ class _Socket extends _SocketBase implements Socket {
int _writeList(List<int> buffer, int offset, int bytes)
native "Socket_WriteList";
+ void _reportError() {
+ // For all errors we close the socket, call the error handler and
+ // disable further calls of the error handler.
+ close();
+ var errorHandler = _handlerMap[_ERROR_EVENT];
+ if (errorHandler != null) {
+ errorHandler();
+ _setHandler(_ERROR_EVENT, null);
+ }
+ }
+
bool _createConnect(String host, int port) native "Socket_CreateConnect";
void set writeHandler(void callback()) {
« no previous file with comments | « runtime/bin/socket.dart ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698