1
0
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:
Paul Pluzhnikov
2015-08-12 23:51:04 -07:00
parent 8a29509dd9
commit 63e952d9be
6 changed files with 67 additions and 5 deletions

View File

@ -149,6 +149,7 @@ __fmemopen (void *buf, size_t len, const char *mode)
{
cookie_io_functions_t iof;
fmemopen_cookie_t *c;
FILE *result;
c = (fmemopen_cookie_t *) calloc (sizeof (fmemopen_cookie_t), 1);
if (c == NULL)
@ -209,7 +210,16 @@ __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;
}
libc_hidden_def (__fmemopen)
versioned_symbol (libc, __fmemopen, fmemopen, GLIBC_2_22);