From 6e6613787d3a8cc24f60a758f7b29f28292ae488 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 10 Sep 2021 00:51:53 +0000 Subject: apr_file_setaside: don't blindly kill the old cleanup and file descriptor. There is no cleanup with APR_FOPEN_NOCLEANUP, so apr_pool_cleanup_kill() can go in the !(old_file->flags & APR_FOPEN_NOCLEANUP) block. The file descriptor can't be invalidated either, the file may be split in multiple buckets and setting aside one shouldn't invalidate the others. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1893204 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/os2/filedup.c | 6 ++---- file_io/unix/filedup.c | 5 ++--- file_io/win32/filedup.c | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'file_io') diff --git a/file_io/os2/filedup.c b/file_io/os2/filedup.c index ff937eb68..15040c7c6 100644 --- a/file_io/os2/filedup.c +++ b/file_io/os2/filedup.c @@ -113,14 +113,12 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, } if (!(old_file->flags & APR_FOPEN_NOCLEANUP)) { + apr_pool_cleanup_kill(old_file->pool, (void *)old_file, + apr_file_cleanup); apr_pool_cleanup_register(p, (void *)(*new_file), apr_file_cleanup, apr_file_cleanup); } - old_file->filedes = -1; - apr_pool_cleanup_kill(old_file->pool, (void *)old_file, - apr_file_cleanup); - return APR_SUCCESS; } diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c index c68d2e970..446642b3f 100644 --- a/file_io/unix/filedup.c +++ b/file_io/unix/filedup.c @@ -179,6 +179,8 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, (*new_file)->fname = apr_pstrdup(p, old_file->fname); } if (!(old_file->flags & APR_FOPEN_NOCLEANUP)) { + apr_pool_cleanup_kill(old_file->pool, (void *)old_file, + apr_unix_file_cleanup); apr_pool_cleanup_register(p, (void *)(*new_file), apr_unix_file_cleanup, ((*new_file)->flags & APR_INHERIT) @@ -186,9 +188,6 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, : apr_unix_child_file_cleanup); } - old_file->filedes = -1; - apr_pool_cleanup_kill(old_file->pool, (void *)old_file, - apr_unix_file_cleanup); #ifndef WAITIO_USES_POLL (*new_file)->pollset = NULL; #endif diff --git a/file_io/win32/filedup.c b/file_io/win32/filedup.c index eaafaff42..9b4730199 100644 --- a/file_io/win32/filedup.c +++ b/file_io/win32/filedup.c @@ -211,15 +211,13 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, (*new_file)->fname = apr_pstrdup(p, old_file->fname); } if (!(old_file->flags & APR_FOPEN_NOCLEANUP)) { + apr_pool_cleanup_kill(old_file->pool, (void *)old_file, + file_cleanup); apr_pool_cleanup_register(p, (void *)(*new_file), file_cleanup, file_cleanup); } - old_file->filehand = INVALID_HANDLE_VALUE; - apr_pool_cleanup_kill(old_file->pool, (void *)old_file, - file_cleanup); - #if APR_FILES_AS_SOCKETS /* Create a pollset with room for one descriptor. */ /* ### check return codes */ -- cgit v1.2.1