Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix #409 Leak of global user vars
(cherry picked from commit 33b71aae0a117707ae3e988a373f9782efb1fbc3)
- Loading branch information
Showing
with
3 additions
and
12 deletions.
-
+3
−11
src/searchd.cpp
-
+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 ); |
|
|
} |
|
|
|
|
|
|
|
struct NamedRefVectorPair_t |
|
|
{ |
|
|
CSphString m_sName; |
|
|
UservarIntSet_c * m_pVal; |
|
|
CSphRefcountedPtr<UservarIntSet_c> m_pVal; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
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 ) ); |
|
|
|
|
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 ); |
|
|