diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-08-12 23:51:04 -0700 |
---|---|---|
committer | Paul Pluzhnikov <ppluzhnikov@google.com> | 2015-08-12 23:51:04 -0700 |
commit | 63e952d9be87db68f0e4164d4a5760b32e77ebff (patch) | |
tree | 652f8bece6a6a04f7618093c9d3dc1b0a398d965 /libio/oldfmemopen.c | |
parent | 8a29509dd9aa179bfe4ef96d49d72f6816ec878f (diff) | |
download | glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.tar.gz glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.tar.xz glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.zip |
Fix BZ #18820 -- fmemopen may leak memory on failure.
Diffstat (limited to 'libio/oldfmemopen.c')
-rw-r--r-- | libio/oldfmemopen.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libio/oldfmemopen.c b/libio/oldfmemopen.c index 8e35672327..88ef8fa7f0 100644 --- a/libio/oldfmemopen.c +++ b/libio/oldfmemopen.c @@ -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 |