# HG changeset patch # User asl # Date 1061235933 0 # Node ID ebabafdc2d94c49236c2b1511156c27b6ab9bd94 # Parent c0cf37c14a8a966baca7a54d5bc87108b8b94606 * src/common/fclose.cxx (fclose): fclose would seg-fault if passed NULL FILE pointer. Now returns error. Also cleaned up some exit paths to call Cyg_libc_stdio_files::unlock() * src/common/fopen.cxx (fopen): Cleaned up some exit paths to call Cyg_libc_stdio_files::unlock() diff --git a/packages/language/c/libc/stdio/current/ChangeLog b/packages/language/c/libc/stdio/current/ChangeLog --- a/packages/language/c/libc/stdio/current/ChangeLog +++ b/packages/language/c/libc/stdio/current/ChangeLog @@ -1,3 +1,12 @@ +2003-08-12 Scott Wilkinson + + * src/common/fclose.cxx (fclose): fclose would seg-fault if passed + NULL FILE pointer. Now returns error. Also cleaned up some exit + paths to call Cyg_libc_stdio_files::unlock() + + * src/common/fopen.cxx (fopen): Cleaned up some exit paths to call + Cyg_libc_stdio_files::unlock() + 2003-06-10 Andrew Lunn Knud Wöhler diff --git a/packages/language/c/libc/stdio/current/src/common/fclose.cxx b/packages/language/c/libc/stdio/current/src/common/fclose.cxx --- a/packages/language/c/libc/stdio/current/src/common/fclose.cxx +++ b/packages/language/c/libc/stdio/current/src/common/fclose.cxx @@ -80,7 +80,13 @@ fclose( FILE *stream ) Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream; int i; Cyg_ErrNo err; - + + if (NULL == real_stream) + { + errno = EBADF; + return EOF; + } + Cyg_libc_stdio_files::lock(); // find the stream in the table @@ -92,8 +98,8 @@ fclose( FILE *stream ) if (i == FOPEN_MAX) // didn't find it { + Cyg_libc_stdio_files::unlock(); errno = EBADF; - return EOF; } // if @@ -101,6 +107,7 @@ fclose( FILE *stream ) if( err != ENOERR ) { + Cyg_libc_stdio_files::unlock(); errno = err; return EOF; } diff --git a/packages/language/c/libc/stdio/current/src/common/fopen.cxx b/packages/language/c/libc/stdio/current/src/common/fopen.cxx --- a/packages/language/c/libc/stdio/current/src/common/fopen.cxx +++ b/packages/language/c/libc/stdio/current/src/common/fopen.cxx @@ -156,6 +156,7 @@ static FILE *fopen_inner( cyg_stdio_hand if (i == FOPEN_MAX) { // didn't find an empty slot errno = EMFILE; cyg_stdio_close( dev ); + Cyg_libc_stdio_files::unlock(); return NULL; } // if @@ -169,6 +170,7 @@ static FILE *fopen_inner( cyg_stdio_hand curr_stream = (Cyg_StdioStream *)malloc(sizeof(*curr_stream)); if (curr_stream == NULL) { cyg_stdio_close( dev ); + Cyg_libc_stdio_files::unlock(); errno = ENOMEM; return NULL; } // if