You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2008/11/19 21:41:38 UTC
svn commit: r719062 - /incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h
Author: aconway
Date: Wed Nov 19 12:41:38 2008
New Revision: 719062
URL: http://svn.apache.org/viewvc?rev=719062&view=rev
Log:
File descriptor leak in ForkedBroker test utility.
Modified:
incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h
Modified: incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h?rev=719062&r1=719061&r2=719062&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/ForkedBroker.h Wed Nov 19 12:41:38 2008
@@ -61,9 +61,7 @@
void kill(int sig=SIGINT) {
if (pid == 0) return;
int savePid = pid;
- pid = 0; // Always reset pid, even in case of an exception below.
- ::close(pipeFds[1]);
-
+ pid = 0; // Reset pid here in case of an exception.
using qpid::ErrnoException;
if (::kill(savePid, sig) < 0)
throw ErrnoException("kill failed");
@@ -79,10 +77,16 @@
private:
+ template <class F> struct OnExit {
+ F fn;
+ OnExit(F f) : fn(f) {}
+ ~OnExit() { fn(); }
+ };
+
void init(const std::vector<const char*>& args) {
using qpid::ErrnoException;
- pid = 0;
port = 0;
+ int pipeFds[2];
if(::pipe(pipeFds) < 0) throw ErrnoException("Can't create pipe");
pid = ::fork();
if (pid < 0) throw ErrnoException("Fork failed");
@@ -94,10 +98,11 @@
if (ferror(f)) throw ErrnoException("Error reading port number from child.");
else throw qpid::Exception("EOF reading port number from child.");
}
+ ::close(pipeFds[0]);
}
else { // child
::close(pipeFds[0]);
- int fd = ::dup2(pipeFds[1], 1);
+ int fd = ::dup2(pipeFds[1], 1); // pipe stdout to the parent.
if (fd < 0) throw ErrnoException("dup2 failed");
const char* prog = "../qpidd";
std::vector<const char*> args2(args);
@@ -109,7 +114,6 @@
}
}
- int pipeFds[2];
pid_t pid;
int port;
};