Skip to content

Commit f42bd02

Browse files
committed
Don't crash on success
Keep request around, as the http/client needs it for cleanup. Calling abort on an already deinit'd request is safe.
1 parent 52634dd commit f42bd02

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/browser/xhr/xhr.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ pub const XMLHttpRequest = struct {
258258
}
259259

260260
pub fn destructor(self: *XMLHttpRequest, _: anytype) void {
261-
const request = &(self.request orelse return);
262-
request.abort();
261+
self._abort();
263262
}
264263

265264
pub fn reset(self: *XMLHttpRequest) void {
@@ -516,7 +515,6 @@ pub const XMLHttpRequest = struct {
516515
return;
517516
}
518517

519-
self.request = null;
520518
self.state = .done;
521519
self.send_flag = false;
522520
self.dispatchEvt("readystatechange");
@@ -541,6 +539,10 @@ pub const XMLHttpRequest = struct {
541539
}
542540

543541
pub fn _abort(self: *XMLHttpRequest) void {
542+
const request = &(self.request orelse return);
543+
// safe to call even if the request is complete
544+
request.abort();
545+
544546
self.onErr(DOMError.Abort);
545547
}
546548

0 commit comments

Comments
 (0)