Skip to content

Commit

Permalink
Fix #409 Leak of global user vars
Browse files Browse the repository at this point in the history
(cherry picked from commit 33b71aae0a117707ae3e988a373f9782efb1fbc3)
  • Loading branch information
klirichek committed Aug 23, 2018
1 parent 7c138f1 commit 6023f26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/searchd.cpp
Expand Up @@ -477,7 +477,7 @@ enum Uservar_e
struct Uservar_t struct Uservar_t
{ {
Uservar_e m_eType { USERVAR_INT_SET }; Uservar_e m_eType { USERVAR_INT_SET };
UservarIntSet_c * m_pVal = nullptr; CSphRefcountedPtr<UservarIntSet_c> m_pVal;
}; };


static CSphMutex g_tUservarsMutex; static CSphMutex g_tUservarsMutex;
Expand Down Expand Up @@ -15899,8 +15899,6 @@ static void UservarAdd ( const CSphString & sName, CSphVector<SphAttr_t> & dVal
// from here, the old value becomes nameless, though // from here, the old value becomes nameless, though
assert ( pVar->m_eType==USERVAR_INT_SET ); assert ( pVar->m_eType==USERVAR_INT_SET );
assert ( pVar->m_pVal ); assert ( pVar->m_pVal );
pVar->m_pVal->Release();
pVar->m_pVal = nullptr;
} else } else
{ {
// create a shiny new variable // create a shiny new variable
Expand All @@ -15911,9 +15909,8 @@ static void UservarAdd ( const CSphString & sName, CSphVector<SphAttr_t> & dVal


// swap in the new value // swap in the new value
assert ( pVar ); assert ( pVar );
assert ( !pVar->m_pVal );
pVar->m_eType = USERVAR_INT_SET; 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 ); pVar->m_pVal->SwapData ( dVal );
} }


Expand Down Expand Up @@ -18574,7 +18571,7 @@ static void PrereadFunc ( void * )
struct NamedRefVectorPair_t struct NamedRefVectorPair_t
{ {
CSphString m_sName; CSphString m_sName;
UservarIntSet_c * m_pVal; CSphRefcountedPtr<UservarIntSet_c> m_pVal;
}; };




Expand Down Expand Up @@ -18638,7 +18635,6 @@ static void SphinxqlStateThreadFunc ( void * )
NamedRefVectorPair_t &tPair = dUservars.Add (); NamedRefVectorPair_t &tPair = dUservars.Add ();
tPair.m_sName = g_hUservars.IterateGetKey (); tPair.m_sName = g_hUservars.IterateGetKey ();
tPair.m_pVal = g_hUservars.IterateGet ().m_pVal; tPair.m_pVal = g_hUservars.IterateGet ().m_pVal;
tPair.m_pVal->AddRef ();
} }
} }
dUservars.Sort ( bind ( &NamedRefVectorPair_t::m_sName ) ); dUservars.Sort ( bind ( &NamedRefVectorPair_t::m_sName ) );
Expand Down Expand Up @@ -18667,10 +18663,6 @@ static void SphinxqlStateThreadFunc ( void * )
tWriter.PutBytes ( sTail, sizeof ( sTail )-1 ); tWriter.PutBytes ( sTail, sizeof ( sTail )-1 );
} }


// release all locked uservars
ARRAY_FOREACH ( i, dUservars )
dUservars[i].m_pVal->Release();

///////////////////////////////// /////////////////////////////////
// writing done, flip the burger // writing done, flip the burger
///////////////////////////////// /////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/sphinxint.h
Expand Up @@ -1709,7 +1709,6 @@ uint64_t sphGetSettingsFNV ( const CSphIndexSettings & tSettings );
/// value container for the intset uservar type /// value container for the intset uservar type
class UservarIntSet_c : public CSphVector<SphAttr_t>, public ISphRefcountedMT class UservarIntSet_c : public CSphVector<SphAttr_t>, public ISphRefcountedMT
{ {
~UservarIntSet_c() = default;
}; };


extern UservarIntSet_c * ( *g_pUservarsHook )( const CSphString & sUservar ); extern UservarIntSet_c * ( *g_pUservarsHook )( const CSphString & sUservar );
Expand Down

0 comments on commit 6023f26

Please sign in to comment.