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/test-fmemopen.c | |
parent | Fix BZ #16734 -- fopen calls mmap to allocate its buffer (diff) | |
download | glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.tar.gz glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.tar.bz2 glibc-63e952d9be87db68f0e4164d4a5760b32e77ebff.zip |
Fix BZ #18820 -- fmemopen may leak memory on failure.
Diffstat (limited to 'libio/test-fmemopen.c')
-rw-r--r-- | libio/test-fmemopen.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/libio/test-fmemopen.c b/libio/test-fmemopen.c index 63ca89f300..e8e757f351 100644 --- a/libio/test-fmemopen.c +++ b/libio/test-fmemopen.c @@ -22,6 +22,32 @@ static char buffer[] = "foobar"; #include <stdio.h> #include <string.h> #include <errno.h> +#include <mcheck.h> + +static int +do_bz18820 (void) +{ + char ch; + FILE *stream; + + stream = fmemopen (&ch, 1, "?"); + if (stream) + { + printf ("fmemopen: expected NULL, got %p\n", stream); + fclose (stream); + return 1; + } + + stream = fmemopen (NULL, 42, "?"); + if (stream) + { + printf ("fmemopen: expected NULL, got %p\n", stream); + fclose (stream); + return 2; + } + + return 0; +} static int do_test (void) @@ -30,6 +56,8 @@ do_test (void) FILE *stream; int ret = 0; + mtrace (); + stream = fmemopen (buffer, strlen (buffer), "r+"); while ((ch = fgetc (stream)) != EOF) @@ -44,7 +72,7 @@ do_test (void) fclose (stream); - return ret; + return ret + do_bz18820 (); } #define TEST_FUNCTION do_test () |