1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

MCOL-371 fix mutex free crash

It is possible for an exception to be thrown when a memory limit is hit
whilst a mutex is lock. That mutex is never unlocked and in Ubuntu 16.04
release build it can cause a crash when freed.

This patch catches the exception, releases the lock and then re-throws.
This commit is contained in:
Andrew Hutchings
2016-10-23 16:12:38 +01:00
parent 4a28e908e6
commit 877dc201bd

View File

@ -348,10 +348,18 @@ void TupleAggregateStep::doThreadedSecondPhaseAggregate(uint32_t threadID)
{
if (!bucketDone[c] && fAgg_mutex[c]->try_lock())
{
if (multiDist)
dynamic_cast<RowAggregationMultiDistinct*>(fAggregators[c].get())->doDistinctAggregation_rowVec(rowBucketVecs[c]);
else
dynamic_cast<RowAggregationDistinct*>(fAggregators[c].get())->doDistinctAggregation_rowVec(rowBucketVecs[c][0]);
try
{
if (multiDist)
dynamic_cast<RowAggregationMultiDistinct*>(fAggregators[c].get())->doDistinctAggregation_rowVec(rowBucketVecs[c]);
else
dynamic_cast<RowAggregationDistinct*>(fAggregators[c].get())->doDistinctAggregation_rowVec(rowBucketVecs[c][0]);
}
catch(...)
{
fAgg_mutex[c]->unlock();
throw;
}
fAgg_mutex[c]->unlock();
bucketDone[c] = true;
rowBucketVecs[c][0].clear();
@ -4301,11 +4309,19 @@ void TupleAggregateStep::threadedAggregateRowGroups(uint32_t threadID)
{
if (!fEndOfResult && !bucketDone[c] && fAgg_mutex[c]->try_lock())
{
didWork = true;
if (multiDist)
dynamic_cast<RowAggregationMultiDistinct*>(fAggregators[c].get())->addRowGroup(&fRowGroupIns[threadID], rowBucketVecs[c]);
else
fAggregators[c]->addRowGroup(&fRowGroupIns[threadID], rowBucketVecs[c][0]);
try
{
didWork = true;
if (multiDist)
dynamic_cast<RowAggregationMultiDistinct*>(fAggregators[c].get())->addRowGroup(&fRowGroupIns[threadID], rowBucketVecs[c]);
else
fAggregators[c]->addRowGroup(&fRowGroupIns[threadID], rowBucketVecs[c][0]);
}
catch(...)
{
fAgg_mutex[c]->unlock();
throw;
}
fAgg_mutex[c]->unlock();
rowBucketVecs[c][0].clear();
bucketDone[c] = true;