mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
avoid possible memory leaks
This commit is contained in:
@@ -368,14 +368,15 @@ pub fn WindowsPipeReader(
|
||||
}
|
||||
|
||||
fn onFileRead(fs: *uv.fs_t) callconv(.C) void {
|
||||
const nread_int = fs.result.int();
|
||||
const result = fs.result;
|
||||
const nread_int = result.int();
|
||||
bun.sys.syslog("onFileRead({}) = {d}", .{ bun.toFD(fs.file.fd), nread_int });
|
||||
if (nread_int == uv.UV_ECANCELED) {
|
||||
// we can be deinit at this point (when closing the reader and calling stopReading)
|
||||
fs.deinit();
|
||||
return;
|
||||
}
|
||||
var this: *This = bun.cast(*This, fs.data);
|
||||
|
||||
bun.sys.syslog("onFileRead({}) = {d}", .{ bun.toFD(fs.file.fd), nread_int });
|
||||
fs.deinit();
|
||||
|
||||
switch (nread_int) {
|
||||
// 0 actually means EOF too
|
||||
@@ -386,7 +387,7 @@ pub fn WindowsPipeReader(
|
||||
// UV_ECANCELED needs to be on the top so we avoid UAF
|
||||
uv.UV_ECANCELED => unreachable,
|
||||
else => {
|
||||
if (fs.result.toError(.read)) |err| {
|
||||
if (result.toError(.read)) |err| {
|
||||
this.flags.is_paused = true;
|
||||
this.onRead(.{ .err = err }, "", .progress);
|
||||
return;
|
||||
@@ -397,7 +398,6 @@ pub fn WindowsPipeReader(
|
||||
if (this.source) |source| {
|
||||
if (source == .file) {
|
||||
const file = source.file;
|
||||
file.fs.deinit();
|
||||
source.setData(this);
|
||||
const buf = this.getReadBufferWithStableMemoryAddress(64 * 1024);
|
||||
file.iov = uv.uv_buf_t.init(buf);
|
||||
|
||||
@@ -1202,9 +1202,15 @@ pub fn WindowsStreamingWriter(
|
||||
}
|
||||
|
||||
fn onFsWriteComplete(fs: *uv.fs_t) callconv(.C) void {
|
||||
if (fs.result.int() == uv.UV_ECANCELED) return;
|
||||
const result = fs.result;
|
||||
if (result.int() == uv.UV_ECANCELED) {
|
||||
fs.deinit();
|
||||
return;
|
||||
}
|
||||
const this = bun.cast(*WindowsWriter, fs.data);
|
||||
if (fs.result.toError(.write)) |err| {
|
||||
|
||||
fs.deinit();
|
||||
if (result.toError(.write)) |err| {
|
||||
this.close();
|
||||
onError(this.parent, err);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user