mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
Fix BZ #18820 -- fmemopen may leak memory on failure.
This commit is contained in:
@ -204,6 +204,7 @@ __old_fmemopen (void *buf, size_t len, const char *mode)
|
||||
{
|
||||
cookie_io_functions_t iof;
|
||||
fmemopen_cookie_t *c;
|
||||
FILE *result;
|
||||
|
||||
if (__glibc_unlikely (len == 0))
|
||||
{
|
||||
@ -259,7 +260,16 @@ __old_fmemopen (void *buf, size_t len, const char *mode)
|
||||
iof.seek = fmemopen_seek;
|
||||
iof.close = fmemopen_close;
|
||||
|
||||
return _IO_fopencookie (c, mode, iof);
|
||||
result = _IO_fopencookie (c, mode, iof);
|
||||
if (__glibc_unlikely (result == NULL))
|
||||
{
|
||||
if (c->mybuffer)
|
||||
free (c->buffer);
|
||||
|
||||
free (c);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
compat_symbol (libc, __old_fmemopen, fmemopen, GLIBC_2_2);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user