#2 bonnie++ 1.03a leaks file descriptors

open
nobody
None
5
2003-05-22
2003-05-22
No

The bonnie++ program leaks file descriptors during the seek test.

The CFileOp::seek_test program creates a local Fork object on the stack. The parent process copy of
the Fork object contains two fds m_read and m_write that contain fd's for communicating with children.
When seek_test exits, since there is no destructor, the fd's are never closed.

The following patch corrects the problem:

diff -rc bonnie++-1.03a/forkit.cpp bonnie++-1.03a-new/forkit.cpp
*** bonnie++-1.03a/forkit.cpp Sun Dec 31 22:26:29 2000
--- bonnie++-1.03a-new/forkit.cpp Mon May 19 16:28:18 2003
***************
*** 19,24 ****
--- 19,36 ----
{
}

+ Fork::~Fork()
+ {
+ if (m_read != -1)
+ {
+ file_close(m_read);
+ }
+ if (m_write != -1)
+ {
+ file_close(m_write);
+ }
+ }
+
#ifdef OS2
// for the benefit of this function and the new Fork class it may create
// the Fork class must do nothing of note in it's constructor or it's
diff -rc bonnie++-1.03a/forkit.h bonnie++-1.03a-new/forkit.h
*** bonnie++-1.03a/forkit.h Sun Oct 13 14:11:15 2002
--- bonnie++-1.03a-new/forkit.h Mon May 19 16:28:39 2003
***************
*** 26,31 ****
--- 26,32 ----
{
public:
Fork();
+ ~Fork();
void go(FUNCTION func, PVOID param, int num);

~
~

Discussion


Log in to post a comment.