Skip to content

Commit 9d63b8e

Browse files
committed
Merge pull request #165 from gpetruc/fix-fclose-slc5
Yes, it looks like `stdOutIsMine_ = false` was missing.
2 parents cbcd15b + fd4b14b commit 9d63b8e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/CloseCoutSentry.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../interface/CloseCoutSentry.h"
22

33
#include <cstdio>
4+
#include <cassert>
45
#include <unistd.h>
56

67
bool CloseCoutSentry::open_ = true;
@@ -22,6 +23,7 @@ CloseCoutSentry::CloseCoutSentry(bool silent) :
2223
}
2324
freopen("/dev/null", "w", stdout);
2425
freopen("/dev/null", "w", stderr);
26+
assert(owner_ == 0);
2527
owner_ = this;
2628
} else {
2729
silent_ = false;
@@ -36,7 +38,10 @@ CloseCoutSentry::~CloseCoutSentry()
3638

3739
void CloseCoutSentry::clear()
3840
{
39-
if (stdOutIsMine_) { fclose(trueStdOut_); trueStdOut_ = 0; }
41+
if (stdOutIsMine_) {
42+
assert(this == owner_);
43+
fclose(trueStdOut_); trueStdOut_ = 0; stdOutIsMine_ = false;
44+
}
4045
if (silent_) {
4146
reallyClear();
4247
silent_ = false;
@@ -70,6 +75,8 @@ FILE *CloseCoutSentry::trueStdOut()
7075
{
7176
if (open_) return stdout;
7277
if (trueStdOut_) return trueStdOut_;
78+
if (owner_ != this && owner_ != 0) return owner_->trueStdOut();
79+
assert(owner_ == this);
7380
stdOutIsMine_ = true;
7481
char buf[50];
7582
sprintf(buf, "/dev/fd/%d", fdOut_); trueStdOut_ = fopen(buf, "w");

0 commit comments

Comments
 (0)