diff options
author | Björn-Egil Dahlberg <[email protected]> | 2013-01-10 16:56:49 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2013-01-10 16:56:49 +0100 |
commit | 20c180d3f207993b004a0b574fd0150d95435a2d (patch) | |
tree | ecff533e35eb34336bca83ec5302192eec1ed6b7 /erts/emulator/drivers/common/efile_drv.c | |
parent | ce1ac29c3dace7fa91845269400105e726fe0d93 (diff) | |
parent | bcbd925da0544249bd31ffab04bd65bdbdc3d10f (diff) | |
download | otp-20c180d3f207993b004a0b574fd0150d95435a2d.tar.gz otp-20c180d3f207993b004a0b574fd0150d95435a2d.tar.bz2 otp-20c180d3f207993b004a0b574fd0150d95435a2d.zip |
Merge branch 'fdm/fix_fd_leak_async_thread_pool/OTP-10677'
* fdm/fix_fd_leak_async_thread_pool/OTP-10677:
Fix fd leak when using async thread pool
Diffstat (limited to 'erts/emulator/drivers/common/efile_drv.c')
-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; } |