core: Fix panic when socket is closed before connecting

This commit is contained in:
sleepycatcoding 2023-07-17 19:09:46 +03:00 committed by Nathan Adams
parent b46cc2aadc
commit 568d8dfe11
1 changed files with 10 additions and 14 deletions

View File

@ -125,25 +125,21 @@ impl<'gc> Sockets<'gc> {
match action { match action {
SocketAction::Connect(handle, success) => { SocketAction::Connect(handle, success) => {
if success { if success {
let target = activation let target = match activation.context.sockets.sockets.get(handle) {
.context Some(socket) => socket.target,
.sockets // Socket must have been closed before we could send event.
.sockets None => continue,
.get(handle) };
.expect("only valid handles in SocketAction")
.target;
let connect_evt = let connect_evt =
EventObject::bare_default_event(&mut activation.context, "connect"); EventObject::bare_default_event(&mut activation.context, "connect");
Avm2::dispatch_event(&mut activation.context, connect_evt, target.into()); Avm2::dispatch_event(&mut activation.context, connect_evt, target.into());
} else { } else {
let target = activation let target = match activation.context.sockets.sockets.get(handle) {
.context Some(socket) => socket.target,
.sockets // Socket must have been closed before we could send event.
.sockets None => continue,
.get(handle) };
.expect("only valid handles in SocketAction")
.target;
let io_error_evt = activation let io_error_evt = activation
.avm2() .avm2()