DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25575>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25575

On shutdown an invalid file handle is causing crash in function 
apr_file_write() on Windows.

           Summary: On shutdown an invalid file handle is causing crash in
                    function apr_file_write() on Windows.
           Product: APR
           Version: 0.9.4
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Major
          Priority: Other
         Component: APR
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


While troubleshooting a crash that occurs while shutting down Aache 2.0.47 on 
Windows XP and Win 2000 I came up with a check that prevents the crash, though 
it doesn't by any means solve the bigger issue described in issue 20462.  Since 
my change involves APR I thought I should create an issue for it showing the 
component as APR. 

My description of problem before seeing issue 20462:

While apache is shutting down a write to a file fails because the mutex value 
has been cleaned up.  It then tries to log this error to an error log file but 
the file handle has been invalidated by this time.  The fix adds a simple check 
for a valid file handle before trying to call the function apr_thread_mutex_lock
() which needs a valid file handle and mutex or it crashes.

File:     srclib/apr/file_io/win32/readwrite.c
Function: apr_file_write

Starting at line 307 I added this check and modifed existing function call to 
check the return code.

if (thefile->filehand == (HANDLE)0 || thefile->filehand == (HANDLE)-1) {
    return (APR_OS_START_SYSERR + ERROR_INVALID_HANDLE);
}
    /* apr_file_lock will mutex the file across processes.
     * The call to apr_thread_mutex_lock is added to avoid
     * a race condition between LockFile and WriteFile 
     * that occasionally leads to deadlocked threads.
     */
     rc = apr_thread_mutex_lock(thefile->mutex);
     if (rc != APR_SUCCESS) {
         return rc;
     }

If you think this is useful then I'd be happy to help out in any way I can.

David Blake
[EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to