Merge pull request #1513 from lightpanda-io/fix_crash_on_double_http_abort

Fix double-free of XHR on double client abort
This commit is contained in:
Karl Seguin
2026-02-11 07:14:01 +08:00
committed by GitHub
2 changed files with 8 additions and 1 deletions

View File

@@ -233,6 +233,7 @@ pub fn send(self: *XMLHttpRequest, body_: ?[]const u8) !void {
.data_callback = httpDataCallback,
.done_callback = httpDoneCallback,
.error_callback = httpErrorCallback,
.shutdown_callback = httpShutdownCallback,
});
page.js.strongRef(self);
@@ -463,6 +464,11 @@ fn httpErrorCallback(ctx: *anyopaque, err: anyerror) void {
self._page.js.weakRef(self);
}
fn httpShutdownCallback(ctx: *anyopaque) void {
const self: *XMLHttpRequest = @ptrCast(@alignCast(ctx));
self._transfer = null;
}
pub fn abort(self: *XMLHttpRequest) void {
self.handleError(error.Abort);
if (self._transfer) |transfer| {

View File

@@ -39,9 +39,10 @@ pub const FetchOpts = struct {
writer: ?*std.Io.Writer = null,
};
pub fn fetch(app: *App, url: [:0]const u8, opts: FetchOpts) !void {
var browser = try Browser.init(app, .{});
const notification = try Notification.init(app.allocator);
defer notification.deinit();
var browser = try Browser.init(app, .{});
defer browser.deinit();
var session = try browser.newSession(notification);