Permalink
Browse files

Fix #409 Leak of global user vars

(cherry picked from commit 33b71aae0a117707ae3e988a373f9782efb1fbc3)
  • Loading branch information...
klirichek committed Aug 21, 2018
1 parent 7c138f1 commit 6023f269b6f2080e4d380b0957605ef8107c8c9f
Showing with 3 additions and 12 deletions.
  1. +3 −11 src/searchd.cpp
  2. +0 −1 src/sphinxint.h
@@ -477,7 +477,7 @@ enum Uservar_e
struct Uservar_t
{
Uservar_e m_eType { USERVAR_INT_SET };
UservarIntSet_c * m_pVal = nullptr;
CSphRefcountedPtr<UservarIntSet_c> m_pVal;
};
static CSphMutex g_tUservarsMutex;
@@ -15899,8 +15899,6 @@ static void UservarAdd ( const CSphString & sName, CSphVector<SphAttr_t> & dVal
// from here, the old value becomes nameless, though
assert ( pVar->m_eType==USERVAR_INT_SET );
assert ( pVar->m_pVal );
pVar->m_pVal->Release();
pVar->m_pVal = nullptr;
} else
{
// create a shiny new variable
@@ -15911,9 +15909,8 @@ static void UservarAdd ( const CSphString & sName, CSphVector<SphAttr_t> & dVal
// swap in the new value
assert ( pVar );
assert ( !pVar->m_pVal );
pVar->m_eType = USERVAR_INT_SET;
pVar->m_pVal = new UservarIntSet_c();
pVar->m_pVal = new UservarIntSet_c(); // previous will be auto-released here
pVar->m_pVal->SwapData ( dVal );
}
@@ -18574,7 +18571,7 @@ static void PrereadFunc ( void * )
struct NamedRefVectorPair_t
{
CSphString m_sName;
UservarIntSet_c * m_pVal;
CSphRefcountedPtr<UservarIntSet_c> m_pVal;
};
@@ -18638,7 +18635,6 @@ static void SphinxqlStateThreadFunc ( void * )
NamedRefVectorPair_t &tPair = dUservars.Add ();
tPair.m_sName = g_hUservars.IterateGetKey ();
tPair.m_pVal = g_hUservars.IterateGet ().m_pVal;
tPair.m_pVal->AddRef ();
}
}
dUservars.Sort ( bind ( &NamedRefVectorPair_t::m_sName ) );
@@ -18667,10 +18663,6 @@ static void SphinxqlStateThreadFunc ( void * )
tWriter.PutBytes ( sTail, sizeof ( sTail )-1 );
}
// release all locked uservars
ARRAY_FOREACH ( i, dUservars )
dUservars[i].m_pVal->Release();
/////////////////////////////////
// writing done, flip the burger
/////////////////////////////////
@@ -1709,7 +1709,6 @@ uint64_t sphGetSettingsFNV ( const CSphIndexSettings & tSettings );
/// value container for the intset uservar type
class UservarIntSet_c : public CSphVector<SphAttr_t>, public ISphRefcountedMT
{
~UservarIntSet_c() = default;
};
extern UservarIntSet_c * ( *g_pUservarsHook )( const CSphString & sUservar );

0 comments on commit 6023f26

Please sign in to comment.