diff options
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/drivers/common/efile_drv.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/erts/emulator/drivers/common/efile_drv.c b/erts/emulator/drivers/common/efile_drv.c index 912f5d3d8b..2ac7f169af 100644 --- a/erts/emulator/drivers/common/efile_drv.c +++ b/erts/emulator/drivers/common/efile_drv.c @@ -439,6 +439,7 @@ struct t_data Efile_error errInfo; int flags; SWord fd; + int is_fd_unused; /**/ Efile_info info; EFILE_DIR_HANDLE dir_handle; /* Handle to open directory. */ @@ -781,11 +782,6 @@ file_start(ErlDrvPort port, char* command) return (ErlDrvData) desc; } -static void free_data(void *data) -{ - EF_FREE(data); -} - static void do_close(int flags, SWord fd) { if (flags & EFILE_COMPRESSED) { erts_gzclose((gzFile)(fd)); @@ -803,6 +799,17 @@ static void invoke_close(void *data) DTRACE_INVOKE_RETURN(FILE_CLOSE); } +static void free_data(void *data) +{ + struct t_data *d = (struct t_data *) data; + + if (d->command == FILE_OPEN && d->is_fd_unused && d->fd != FILE_FD_INVALID) { + do_close(d->flags, d->fd); + } + + EF_FREE(data); +} + /********************************************************************* * Driver entry point -> stop */ @@ -1862,6 +1869,9 @@ static void invoke_open(void *data) } d->result_ok = status; + if (!status) { + d->fd = FILE_FD_INVALID; + } DTRACE_INVOKE_RETURN(FILE_OPEN); } @@ -2373,8 +2383,10 @@ file_async_ready(ErlDrvData e, ErlDrvThreadData data) if (!d->result_ok) { reply_error(desc, &d->errInfo); } else { + ASSERT(d->is_fd_unused); desc->fd = d->fd; desc->flags = d->flags; + d->is_fd_unused = 0; reply_Uint(desc, d->fd); } free_data(data); @@ -2745,6 +2757,7 @@ file_output(ErlDrvData e, char* buf, ErlDrvSizeT count) d->invoke = invoke_open; d->free = free_data; d->level = 2; + d->is_fd_unused = 1; goto done; } |