libstdc++/9964: filebuf::close() sometimes fails to close file.

peturr02@ru.is peturr02@ru.is
Wed Mar 5 13:26:00 GMT 2003


>Number:         9964
>Category:       libstdc++
>Synopsis:       filebuf::close() sometimes fails to close file.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 05 12:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
It seems that if the call to _M_really_overflow in filebuf::close() fails, then close() doesn't close the file and doesn't delete the buffer.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="closebug.cc"
Content-Disposition: inline; filename="closebug.cc"

#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fstream>

#undef NDEBUG
#include <cassert>

int main()
{
	using namespace std;

	signal(SIGPIPE, SIG_IGN);
	unlink("xxx");
  
	if (0 != mkfifo("xxx", S_IRWXU))
	{
		assert(false);
	}
	
	int fval = fork();
	if (fval == -1)
	{
		unlink("xxx");
		assert(false);
	}
	else if (fval == 0)
	{
		filebuf fbin;
		fbin.open("xxx", ios_base::in);
		sleep(1);
		fbin.close();
		exit(0);
	}

	filebuf fb;
	fb.open("xxx", ios_base::out | ios_base::trunc);
	assert(fb.is_open());
	sleep(2);
	fb.sputc('a');
	filebuf* p = fb.close();
	assert(!p);
	assert(!fb.is_open());

	return 0;
}



More information about the Gcc-bugs mailing list