8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 00:43:02 +01:00

Fixed a bug, privately reported by Pavel Zotov - segfault when closing trace

This commit is contained in:
alexpeshkoff 2014-05-06 12:25:35 +00:00
parent 2fdac342a0
commit d83d4d084a
2 changed files with 20 additions and 15 deletions

View File

@ -3761,7 +3761,6 @@ void JService::freeEngineData(IStatus* user_status)
validateHandle(svc); validateHandle(svc);
svc->detach(); svc->detach();
svc = NULL;
} }
catch (const Exception& ex) catch (const Exception& ex)
{ {

View File

@ -213,9 +213,11 @@ bool Service::SafeMutexLock::lock()
Service::ExistenceGuard::ExistenceGuard(Service* svc, const char* from) Service::ExistenceGuard::ExistenceGuard(Service* svc, const char* from)
: SafeMutexLock(svc, from) : SafeMutexLock(svc, from)
{ {
if (!lock()) bool lck = lock();
if (!lck)
{ {
// could not lock service // could not lock service
jSvc->mutex.leave();
Arg::Gds(isc_bad_svc_handle).raise(); Arg::Gds(isc_bad_svc_handle).raise();
} }
} }
@ -233,29 +235,26 @@ Service::ExistenceGuard::~ExistenceGuard()
} }
Service::UnlockGuard::UnlockGuard(Service* svc, const char* from) Service::UnlockGuard::UnlockGuard(Service* svc, const char* from)
: SafeMutexLock(svc, from), locked(true), doLock(true) : SafeMutexLock(svc, from), locked(false), doLock(false)
{ {
jSvc->mutex.leave(); jSvc->mutex.leave();
locked = false; doLock = true;
} }
bool Service::UnlockGuard::enter() bool Service::UnlockGuard::enter()
{ {
doLock = false; if (doLock)
if (!locked)
{ {
if (!lock()) locked = lock();
{ doLock = false;
return false;
}
locked = true;
} }
return true;
return locked;
} }
Service::UnlockGuard::~UnlockGuard() Service::UnlockGuard::~UnlockGuard()
{ {
if (doLock && (!locked) && (!lock())) if (!enter())
{ {
// could not lock service // could not lock service
DtorException::devHalt(); DtorException::devHalt();
@ -954,6 +953,9 @@ Service::~Service()
delete svc_trace_manager; delete svc_trace_manager;
svc_trace_manager = NULL; svc_trace_manager = NULL;
fb_assert(jSvc->mutex.locked());
jSvc->svc = NULL;
} }
@ -1983,14 +1985,18 @@ THREAD_ENTRY_DECLARE Service::run(THREAD_ENTRY_PARAM arg)
try try
{ {
Service* svc = (Service*)arg; Service* svc = (Service*)arg;
RefPtr<JService> ref(svc->jSvc);
int exit_code = svc->svc_service_run->serv_thd(svc); int exit_code = svc->svc_service_run->serv_thd(svc);
svc->started(); svc->started();
svc->svc_sem_full.release(); svc->svc_sem_full.release();
svc->finish(SVC_finished); svc->finish(SVC_finished);
} }
catch(const Exception&) catch(const Exception& ex)
{ /* Not much we can do here */ } {
// Not much we can do here
iscLogException("Exception in Service::run():", ex);
}
return (THREAD_ENTRY_RETURN)(IPTR) exit_code; return (THREAD_ENTRY_RETURN)(IPTR) exit_code;
} }