Ran into this while running the regression suite for another patch. The regression test for open_memstream causes a SIGBUS because it closes the stream too early.
Replaced fclose with fflush since they both update pbuf and psize. Added a similar check for fclose at the end. Index: regress/lib/libc/open_memstream/open_memstreamtest.c =================================================================== RCS file: /cvs/src/regress/lib/libc/open_memstream/open_memstreamtest.c,v retrieving revision 1.3 diff -u -p -d -r1.3 open_memstreamtest.c --- regress/lib/libc/open_memstream/open_memstreamtest.c 28 Mar 2013 09:35:58 -0000 1.3 +++ regress/lib/libc/open_memstream/open_memstreamtest.c 18 Jul 2014 02:17:58 -0000 @@ -127,8 +127,8 @@ main(void) failures++; } - if (fclose(fp) == EOF) { - warnx("fclose failed. (17)"); + if (fflush(fp) == EOF) { + warnx("fflush failed. (17)"); failures++; } @@ -156,6 +156,22 @@ main(void) if (ftell(fp) != 7) { warnx("failed seeking backward. (22)"); + failures++; + } + + if (fseek(fp, 5, SEEK_CUR) != 0) { + warnx("failed to fseek. (23)"); + failures++; + } + + if (fclose(fp) == EOF) { + warnx("fclose failed. (24)"); + failures++; + } + + if (size != 12) { + warnx("failed, size %zu should be %u. (25)", + size, 12); failures++; }