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

@ -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 ()