cpp: Do not close stdout/stderr when destroying EditInteractor
* lang/cpp/src/editinteractor.cpp (EditInteractor::Private): Initialize members 'state' and 'debug' in-class. Add member 'debugNeedsClosing'. (EditInteractor::Private::Private): Remove members initializers. Remember if 'debug' needs to be closed. (EditInteractor::Private::~Private): Only close 'debug' if it needs to be closed. -- This fixes the problem that after destroying an edit interactor all debug output went to /dev/null instead of stderr (or stdout) if one enabled debugging of the edit interactors with GPGMEPP_INTERACTOR_DEBUG set to stderr (or stdout).
This commit is contained in:
parent
f0858e45b0
commit
58a217b108
@ -62,9 +62,10 @@ public:
|
||||
~Private();
|
||||
|
||||
private:
|
||||
unsigned int state;
|
||||
unsigned int state = StartState;
|
||||
Error error;
|
||||
std::FILE *debug;
|
||||
std::FILE *debug = nullptr;
|
||||
bool debugNeedsClosing = false;
|
||||
};
|
||||
|
||||
class GpgME::CallbackHelper
|
||||
@ -174,10 +175,7 @@ static gpgme_error_t edit_interactor_callback(void *opaque, gpgme_status_code_t
|
||||
const gpgme_edit_cb_t GpgME::edit_interactor_callback = ::edit_interactor_callback;
|
||||
|
||||
EditInteractor::Private::Private(EditInteractor *qq)
|
||||
: q(qq),
|
||||
state(StartState),
|
||||
error(),
|
||||
debug(nullptr)
|
||||
: q(qq)
|
||||
{
|
||||
const char *debug_env = std::getenv("GPGMEPP_INTERACTOR_DEBUG");
|
||||
if (!debug_env) {
|
||||
@ -189,12 +187,13 @@ EditInteractor::Private::Private(EditInteractor *qq)
|
||||
debug = stderr;
|
||||
} else if (debug_env) {
|
||||
debug = std::fopen(debug_env, "a+");
|
||||
debugNeedsClosing = true;
|
||||
}
|
||||
}
|
||||
|
||||
EditInteractor::Private::~Private()
|
||||
{
|
||||
if (debug) {
|
||||
if (debug && debugNeedsClosing) {
|
||||
std::fclose(debug);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user