Skip to content

Commit b92c084

Browse files
committed
Cleanup batches inside the engine if they were not released explicitly before disconnection. This avoids a resource leak (it's mostly about TempSpace). (#8341)
1 parent 59b01c2 commit b92c084

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/dsql/DsqlBatch.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,20 @@ DsqlBatch::DsqlBatch(DsqlDmlRequest* req, const dsql_msg* /*message*/, IMessageM
161161

162162
// assign initial default BPB
163163
setDefBpb(FB_NELEM(initBlobParameters), initBlobParameters);
164-
}
165164

165+
if (const auto att = m_dsqlRequest->req_dbb->dbb_attachment)
166+
att->registerBatch(this);
167+
}
166168

167169
DsqlBatch::~DsqlBatch()
168170
{
169171
if (m_batch)
170172
m_batch->resetHandle();
171173
if (m_dsqlRequest)
172-
m_dsqlRequest->req_batch = NULL;
174+
m_dsqlRequest->req_batch = nullptr;
175+
176+
if (const auto att = m_dsqlRequest->req_dbb->dbb_attachment)
177+
att->deregisterBatch(this);
173178
}
174179

175180
Attachment* DsqlBatch::getAttachment() const

src/jrd/Attachment.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "../jrd/replication/Applier.h"
4848
#include "../jrd/replication/Manager.h"
4949

50+
#include "../dsql/DsqlBatch.h"
5051
#include "../dsql/DsqlStatementCache.h"
5152

5253
#include "../common/classes/fb_string.h"
@@ -287,9 +288,6 @@ Jrd::Attachment::~Attachment()
287288

288289
delete att_trace_manager;
289290

290-
for (unsigned n = 0; n < att_batches.getCount(); ++n)
291-
att_batches[n]->resetHandle();
292-
293291
for (Function** iter = att_functions.begin(); iter < att_functions.end(); ++iter)
294292
{
295293
Function* const function = *iter;
@@ -448,6 +446,12 @@ void Jrd::Attachment::storeBinaryBlob(thread_db* tdbb, jrd_tra* transaction,
448446
blob->BLB_close(tdbb);
449447
}
450448

449+
void Jrd::Attachment::releaseBatches()
450+
{
451+
while (att_batches.hasData())
452+
delete att_batches.pop();
453+
}
454+
451455
void Jrd::Attachment::releaseGTTs(thread_db* tdbb)
452456
{
453457
if (!att_relations)

src/jrd/Attachment.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ class Attachment : public pool_alloc<type_att>
729729
void storeBinaryBlob(thread_db* tdbb, jrd_tra* transaction, bid* blobId,
730730
const Firebird::ByteChunk& chunk);
731731

732+
void releaseBatches();
732733
void releaseGTTs(thread_db* tdbb);
733734
void resetSession(thread_db* tdbb, jrd_tra** traHandle);
734735

@@ -791,12 +792,12 @@ class Attachment : public pool_alloc<type_att>
791792
}
792793

793794
// batches control
794-
void registerBatch(JBatch* b)
795+
void registerBatch(DsqlBatch* b)
795796
{
796797
att_batches.add(b);
797798
}
798799

799-
void deregisterBatch(JBatch* b)
800+
void deregisterBatch(DsqlBatch* b)
800801
{
801802
att_batches.findAndRemove(b);
802803
}
@@ -859,7 +860,7 @@ class Attachment : public pool_alloc<type_att>
859860
unsigned int att_stmt_timeout; // milliseconds
860861
Firebird::RefPtr<Firebird::TimerImpl> att_idle_timer;
861862

862-
Firebird::Array<JBatch*> att_batches;
863+
Firebird::Array<DsqlBatch*> att_batches;
863864
InitialOptions att_initial_options; // Initial session options
864865
DebugOptions att_debug_options;
865866
Firebird::AutoPtr<ProfilerManager> att_profiler_manager; // ProfilerManager

src/jrd/jrd.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6039,7 +6039,6 @@ JBatch* JStatement::createBatch(Firebird::CheckStatusWrapper* status, Firebird::
60396039
batch = FB_NEW JBatch(dsqlBatch, this, inMetadata);
60406040
batch->addRef();
60416041
dsqlBatch->setInterfacePtr(batch);
6042-
tdbb->getAttachment()->registerBatch(batch);
60436042
}
60446043
catch (const Exception& ex)
60456044
{
@@ -6115,9 +6114,6 @@ void JBatch::freeEngineData(Firebird::CheckStatusWrapper* user_status)
61156114

61166115
try
61176116
{
6118-
Attachment* att = getAttachment()->getHandle();
6119-
if (att)
6120-
att->deregisterBatch(this);
61216117
delete batch;
61226118
batch = nullptr;
61236119
}
@@ -7691,6 +7687,8 @@ void release_attachment(thread_db* tdbb, Jrd::Attachment* attachment, XThreadEns
76917687
if (attachment->att_event_session)
76927688
dbb->eventManager()->deleteSession(attachment->att_event_session);
76937689

7690+
attachment->releaseBatches();
7691+
76947692
// CMP_release() changes att_requests.
76957693
while (attachment->att_requests.hasData())
76967694
CMP_release(tdbb, attachment->att_requests.back());

0 commit comments

Comments
 (0)