avoid possible memory leaks

This commit is contained in:
cirospaciari
2024-03-29 20:03:14 -03:00
parent bab8d1bc96
commit 19fe6db6de
2 changed files with 14 additions and 8 deletions

View File

@@ -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);

View File

@@ -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;