diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-13 21:08:49 -0400 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-29 20:35:00 -0400 |
commit | bcd0e854eaed244e0d40872262b65f47afff29c4 (patch) | |
tree | 4e212b410dcf208c97c54fd4b1c6f39c74a291dd /libio/libioP.h | |
parent | e930b89df7c263f3ceec20f085e06723fd1cb562 (diff) | |
download | glibc-bcd0e854eaed244e0d40872262b65f47afff29c4.tar.gz glibc-bcd0e854eaed244e0d40872262b65f47afff29c4.tar.xz glibc-bcd0e854eaed244e0d40872262b65f47afff29c4.zip |
ungetc: Fix backup buffer leak on program exit [BZ #27821]
If a file descriptor is left unclosed and is cleaned up by _IO_cleanup on exit, its backup buffer remains unfreed, registering as a leak in valgrind. This is not strictly an issue since (1) the program should ideally be closing the stream once it's not in use and (2) the program is about to exit anyway, so keeping the backup buffer around a wee bit longer isn't a real problem. Free it anyway to keep valgrind happy when the streams in question are the standard ones, i.e. stdout, stdin or stderr. Also, the _IO_have_backup macro checks for _IO_save_base, which is a roundabout way to check for a backup buffer instead of directly looking for _IO_backup_base. The roundabout check breaks when the main get area has not been used and user pushes a char into the backup buffer with ungetc. Fix this to use the _IO_backup_base directly. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Carlos O'Donell <carlos@redhat.com> (cherry picked from commit 3e1d8d1d1dca24ae90df2ea826a8916896fc7e77) (cherry picked from commit b9f72bd5de931eac39219018c2fa319a449bb2cf)
Diffstat (limited to 'libio/libioP.h')
-rw-r--r-- | libio/libioP.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libio/libioP.h b/libio/libioP.h index ba4fdbd200..bef3324ffb 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -529,8 +529,8 @@ extern void _IO_old_init (FILE *fp, int flags) __THROW; ((__fp)->_wide_data->_IO_write_base \ = (__fp)->_wide_data->_IO_write_ptr = __p, \ (__fp)->_wide_data->_IO_write_end = (__ep)) -#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL) -#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL) +#define _IO_have_backup(fp) ((fp)->_IO_backup_base != NULL) +#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_backup_base != NULL) #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP) #define _IO_have_markers(fp) ((fp)->_markers != NULL) #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base) |