Skip to content

Commit 77e954a

Browse files
committed
Fix GH-8923: error_log on Windows can hold the file write lock
On Windows, closing a file which is locked may not immediately remove the lock. The `LockFileEx()` documentation states: | Therefore, it is recommended that your process explicitly unlock all | files it has locked when it terminates. We comply, and also use the macro `LOCK_EX` instead of the magic number `2`. Closes GH-8925.
1 parent 7c3dfbb commit 77e954a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2022, PHP 8.0.22
44

5+
- Core:
6+
. Fixed bug GH-8923 (error_log on Windows can hold the file write lock). (cmb)
7+
58
- Date:
69
. Fixed bug #80047 (DatePeriod doesn't warn with custom DateTimeImmutable).
710
(Derick)

main/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,10 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int sys
837837
#endif
838838
len = spprintf(&tmp, 0, "[%s] %s%s", ZSTR_VAL(error_time_str), log_message, PHP_EOL);
839839
#ifdef PHP_WIN32
840-
php_flock(fd, 2);
840+
php_flock(fd, LOCK_EX);
841841
/* XXX should eventually write in a loop if len > UINT_MAX */
842842
php_ignore_value(write(fd, tmp, (unsigned)len));
843+
php_flock(fd, LOCK_UN);
843844
#else
844845
php_ignore_value(write(fd, tmp, len));
845846
#endif

0 commit comments

Comments
 (0)