Skip to content

Commit

Permalink
Merge pull request #9858 from brave/maxk-cr93fu-fix-webtorrent-crash
Browse files Browse the repository at this point in the history
[cr93 followup] Fix for webtorrent crash.
  • Loading branch information
mkarolin committed Aug 26, 2021
1 parent e059ea9 commit 413acfc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc
index fcba8ac797b18084efd5a79ae7cdf25487a61407..abf5c544601b32ca6898f64b9bd3927dceff4a41 100644
--- a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc
+++ b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc
@@ -256,15 +256,15 @@ SocketsTcpServerGetInfoFunction::~SocketsTcpServerGetInfoFunction() = default;
ExtensionFunction::ResponseAction SocketsTcpServerGetInfoFunction::Work() {
std::unique_ptr<sockets_tcp_server::GetInfo::Params> params =
sockets_tcp_server::GetInfo::Params::Create(*args_);
- EXTENSION_FUNCTION_VALIDATE(params_.get());
+ EXTENSION_FUNCTION_VALIDATE(params.get());

- ResumableTCPServerSocket* socket = GetTcpSocket(params_->socket_id);
+ ResumableTCPServerSocket* socket = GetTcpSocket(params->socket_id);
if (!socket) {
return RespondNow(Error(kSocketNotFoundError));
}

sockets_tcp_server::SocketInfo socket_info =
- CreateSocketInfo(params_->socket_id, socket);
+ CreateSocketInfo(params->socket_id, socket);
return RespondNow(
ArgumentList(sockets_tcp_server::GetInfo::Results::Create(socket_info)));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h
index 39d68080d449de6a3de282afe4d6335652402e06..d60fa8bbe677c83037f26c5b3cfd286d6a79bd8a 100644
--- a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h
+++ b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h
@@ -134,9 +134,6 @@ class SocketsTcpServerGetInfoFunction : public TCPServerSocketApiFunction {

// SocketApiFunction:
ResponseAction Work() override;
-
- private:
- std::unique_ptr<sockets_tcp_server::GetInfo::Params> params_;
};

class SocketsTcpServerGetSocketsFunction : public TCPServerSocketApiFunction {
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/extensions/test/data/sockets_tcp_server/api/background.js b/extensions/test/data/sockets_tcp_server/api/background.js
index 8a2ff5ee95c74b1cc4e9a9e6bf62db889fe83309..f25b1e7dead44c84bc3019103a95a3c9101f9a91 100644
--- a/extensions/test/data/sockets_tcp_server/api/background.js
+++ b/extensions/test/data/sockets_tcp_server/api/background.js
@@ -43,6 +43,11 @@ var testSocketListening = function() {
function onServerSocketCreate(socketInfo) {
console.log("Server socket created: sd=" + socketInfo.socketId);
socketId = socketInfo.socketId;
+ chrome.sockets.tcpServer.getInfo(socketId, onGetInfo);
+ }
+
+ function onGetInfo(socketInfo) {
+ chrome.test.assertEq(socketInfo.socketId, socketId);
chrome.sockets.tcpServer.listen(socketId, address, port, onListen);
}

0 comments on commit 413acfc

Please sign in to comment.