From 65d548bfe6bac1d28437bafffb1c5af9da38e00d Mon Sep 17 00:00:00 2001 From: wessels <> Date: Thu, 20 Aug 1998 22:04:07 +0000 Subject: [PATCH] file_close should call the read_handler if set so we can free dread_ctrl state --- src/disk.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/disk.cc b/src/disk.cc index 4cfdb7554a..00b579eaa6 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,7 +1,7 @@ /* - * $Id: disk.cc,v 1.128 1998/08/18 22:42:18 wessels Exp $ + * $Id: disk.cc,v 1.129 1998/08/20 16:04:07 wessels Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -127,6 +127,7 @@ void file_close(int fd) { fde *F = &fd_table[fd]; + PF *callback; #if USE_ASYNC_IO if (fd < 0) { debug(6, 0) ("file_close: FD less than zero: %d\n", fd); @@ -136,11 +137,20 @@ file_close(int fd) assert(fd >= 0); #endif assert(F->open); + if ((callback = F->read_handler)) { + F->read_handler = NULL; + callback(-1, F->read_data); + } if (F->flags.write_daemon) { F->flags.close_request = 1; debug(6, 2) ("file_close: FD %d, delaying close\n", fd); return; } + /* + * Assert there is no write callback. Otherwise we might be + * leaking write state data by closing the descriptor + */ + assert(F->write_handler == NULL); #if USE_ASYNC_IO aioClose(fd); #else @@ -427,6 +437,14 @@ diskHandleRead(int fd, void *data) #ifdef OPTIMISTIC_IO assert(!F->flags.calling_io_handler); #endif /* OPTIMISTIC_IO */ + /* + * FD < 0 indicates premature close; we just have to free + * the state data. + */ + if (fd < 0) { + memFree(MEM_DREAD_CTRL, ctrl_dat); + return; + } #if USE_ASYNC_IO aioRead(fd, ctrl_dat->offset, -- 2.47.3