Permalink
Browse files

Fix #383 leak of json sorting col expr in local/remote schema (valgrind)

  • Loading branch information...
klirichek committed Aug 12, 2018
1 parent 943e299 commit 02dbdd6f1d0b72e7e458ebebdd2c67f989577e6b
Showing with 20 additions and 7 deletions.
  1. +2 −4 src/searchd.cpp
  2. +5 −0 src/sphinx.h
  3. +11 −2 src/sphinxsort.cpp
  4. +2 −1 src/sphinxstd.h
@@ -5399,8 +5399,6 @@ static int KillAllDupes ( ISphMatchSorter * pSorter, AggrResult_t & tRes )
tRes.m_dMatches.Reset ();
sphFlattenQueue ( pSorter, &tRes, -1 );
SafeDelete ( pSorter );
return iDupes;
}
@@ -5848,7 +5846,7 @@ bool MinimizeAggrResult ( AggrResult_t & tRes, CSphQuery & tQuery, int iLocals,
SphQueueSettings_t tQueueSettings ( tQuery, tRes.m_tSchema, tRes.m_sError );
tQueueSettings.m_bComputeItems = false;
tQueueSettings.m_pAggrFilter = pAggrFilter;
ISphMatchSorter * pSorter = sphCreateQueue ( tQueueSettings );
CSphScopedPtr<ISphMatchSorter> pSorter ( sphCreateQueue ( tQueueSettings ) );
// restore outer order related patches, or it screws up the query log
if ( tQuery.m_bHasOuter )
@@ -5897,7 +5895,7 @@ bool MinimizeAggrResult ( AggrResult_t & tRes, CSphQuery & tQuery, int iLocals,
}
// do the sort work!
tRes.m_iTotalMatches -= KillAllDupes ( pSorter, tRes );
tRes.m_iTotalMatches -= KillAllDupes ( pSorter.Ptr(), tRes );
}
// apply outer order clause to single result set
@@ -3025,6 +3025,11 @@ struct CSphMatchComparatorState
}
}
~CSphMatchComparatorState ()
{
for ( ISphExpr *&pExpr : m_tSubExpr ) SafeRelease( pExpr );
}
/// check if any of my attrs are bitfields
bool UsesBitfields ()
{
@@ -70,6 +70,7 @@ void ISphMatchSorter::SetSchema ( ISphSchema * pSchema )
void ISphMatchSorter::SetState ( const CSphMatchComparatorState & tState )
{
m_tState = tState;
for ( ISphExpr *&pExpr : m_tState.m_tSubExpr ) SafeAddRef ( pExpr );
m_tState.m_iNow = (DWORD) time ( nullptr );
}
@@ -4475,7 +4476,10 @@ struct ExprSortJson2StringPtr_c : public ISphExpr
: m_pStrings ( nullptr )
, m_tJsonCol ( tLocator )
, m_pExpr ( pExpr )
{}
{
if ( pExpr ) // adopt the expression
pExpr->AddRef();
}
bool IsDataPtrAttr () const final { return true; }
@@ -4621,7 +4625,12 @@ static void SetupSortRemap ( CSphRsetSchema & tSorterSchema, CSphMatchComparator
CSphColumnInfo tRemapCol ( sRemapCol.cstr(), bIsJson ? SPH_ATTR_STRINGPTR : SPH_ATTR_BIGINT );
tRemapCol.m_eStage = SPH_EVAL_PRESORT;
if ( bIsJson )
tRemapCol.m_pExpr = bIsFunc ? tState.m_tSubExpr[i] : new ExprSortJson2StringPtr_c ( tState.m_tLocator[i], tState.m_tSubExpr[i] );
if ( bIsFunc )
{
tRemapCol.m_pExpr = tState.m_tSubExpr[i];
tRemapCol.m_pExpr->AddRef();
} else
tRemapCol.m_pExpr = new ExprSortJson2StringPtr_c ( tState.m_tLocator[i], tState.m_tSubExpr[i] );
else
tRemapCol.m_pExpr = new ExprSortStringAttrFixup_c ( tState.m_tLocator[i] );
@@ -2363,6 +2363,7 @@ class CSphScopedPtr : public ISphNoncopyable
~CSphScopedPtr () { SafeDelete ( m_pPtr ); }
T * operator -> () const { return m_pPtr; }
T * Ptr () const { return m_pPtr; }
explicit operator bool () const { return m_pPtr!=nullptr; }
CSphScopedPtr & operator = ( T * pPtr ) { SafeDelete ( m_pPtr ); m_pPtr = pPtr; return *this; }
T * LeakPtr () { T * pPtr = m_pPtr; m_pPtr = NULL; return pPtr; }
void ReplacePtr ( T * pPtr ) { m_pPtr = pPtr; }
@@ -2416,7 +2417,7 @@ class CSphRefcountedPtr
~CSphRefcountedPtr () { SafeRelease ( m_pPtr ); }
T * operator -> () const { return m_pPtr; }
explicit operator bool() const { return m_pPtr!=nullptr; }
explicit operator bool() const { return m_pPtr!=nullptr; }
operator T * () const { return m_pPtr; }
// drop the ownership and reset pointer

0 comments on commit 02dbdd6

Please sign in to comment.