From 9c1d258b62eb402352758b32e21175782850fe26 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Thu, 26 May 2016 12:21:37 +0100 Subject: [PATCH] mem leak in active chart --- .../other-builds/moses2/SCFG/ActiveChart.h | 25 +++++++++++++------ .../Memory/PhraseTableMemory.cpp | 6 ++--- .../Memory/PhraseTableMemory.h | 9 ++++--- .../TranslationModel/UnknownWordPenalty.cpp | 2 +- contrib/other-builds/moses2/Vector.h | 5 ++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/contrib/other-builds/moses2/SCFG/ActiveChart.h b/contrib/other-builds/moses2/SCFG/ActiveChart.h index 43f06716f..9779fd814 100644 --- a/contrib/other-builds/moses2/SCFG/ActiveChart.h +++ b/contrib/other-builds/moses2/SCFG/ActiveChart.h @@ -23,6 +23,7 @@ public: const SCFG::Word *word; const Moses2::HypothesisColl *hypos; + SymbolBindElement() {} SymbolBindElement(const Range *range, const SCFG::Word *word, const Moses2::HypothesisColl *hypos); bool operator==(const SymbolBindElement &compare) const @@ -41,11 +42,17 @@ class SymbolBind friend std::ostream& operator<<(std::ostream &, const SymbolBind &); public: - std::vector coll; + Vector coll; size_t numNT; - SymbolBind() - :numNT(0) + SymbolBind(MemPool &pool) + :coll(pool) + ,numNT(0) + {} + + SymbolBind(MemPool &pool, const SymbolBind ©) + :coll(copy.coll) + ,numNT(copy.numNT) {} std::vector GetNTElements() const; @@ -65,14 +72,16 @@ inline size_t hash_value(const SymbolBind &obj) class ActiveChartEntry { public: - SymbolBind symbolBinds; + SymbolBind *symbolBinds; - ActiveChartEntry() + ActiveChartEntry(MemPool &pool) + :symbolBinds(new (pool.Allocate()) SymbolBind(pool)) {} - ActiveChartEntry(const ActiveChartEntry &prevEntry) - :symbolBinds(prevEntry.symbolBinds) - {} + ActiveChartEntry(MemPool &pool, const ActiveChartEntry &prevEntry) + { + symbolBinds = new (pool.Allocate()) SymbolBind(pool, *prevEntry.symbolBinds); + } protected: }; diff --git a/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.cpp b/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.cpp index 8c21f7070..8b42bfe8e 100644 --- a/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.cpp +++ b/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.cpp @@ -152,7 +152,7 @@ TargetPhrases* PhraseTableMemory::Lookup(const Manager &mgr, MemPool &pool, void PhraseTableMemory::InitActiveChart(MemPool &pool, SCFG::InputPath &path) const { size_t ptInd = GetPtInd(); - ActiveChartEntryMem *chartEntry = new (pool.Allocate()) ActiveChartEntryMem(*m_rootSCFG); + ActiveChartEntryMem *chartEntry = new (pool.Allocate()) ActiveChartEntryMem(pool, *m_rootSCFG); path.AddActiveChartEntry(ptInd, chartEntry); } @@ -305,9 +305,9 @@ void PhraseTableMemory::LookupGivenNode( if (nextNode) { // new entries - ActiveChartEntryMem *chartEntry = new (pool.Allocate()) ActiveChartEntryMem(*nextNode, prevEntry); + ActiveChartEntryMem *chartEntry = new (pool.Allocate()) ActiveChartEntryMem(pool, *nextNode, prevEntry); - SCFG::SymbolBind &symbolBind = chartEntry->symbolBinds; + SCFG::SymbolBind &symbolBind = *chartEntry->symbolBinds; symbolBind.Add(subPhrasePath.range, wordSought, hypos); path.AddActiveChartEntry(ptInd, chartEntry); diff --git a/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.h b/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.h index 03ff08992..5a8bb5d0d 100644 --- a/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.h +++ b/contrib/other-builds/moses2/TranslationModel/Memory/PhraseTableMemory.h @@ -28,17 +28,20 @@ class PhraseTableMemory: public PhraseTable ////////////////////////////////////// class ActiveChartEntryMem : public SCFG::ActiveChartEntry { + typedef SCFG::ActiveChartEntry Parent; public: const PhraseTableMemory::SCFGNODE &node; - ActiveChartEntryMem(const PhraseTableMemory::SCFGNODE &vnode) - :node(vnode) + ActiveChartEntryMem(MemPool &pool, const PhraseTableMemory::SCFGNODE &vnode) + :Parent(pool) + ,node(vnode) {} ActiveChartEntryMem( + MemPool &pool, const PhraseTableMemory::SCFGNODE &vnode, const ActiveChartEntry &prevEntry) - :ActiveChartEntry(prevEntry) + :Parent(prevEntry) ,node(vnode) {} }; diff --git a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp index 3efdba1d5..6581369a7 100644 --- a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp +++ b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp @@ -132,7 +132,7 @@ void UnknownWordPenalty::Lookup(MemPool &pool, size_t endPos = path.range.GetEndPos(); const SCFG::InputPath &subPhrasePath = *mgr.GetInputPaths().GetMatrix().GetValue(endPos, 1); - SCFG::SymbolBind symbolBind; + SCFG::SymbolBind symbolBind(pool); symbolBind.Add(subPhrasePath.range, lastWord, NULL); path.AddTargetPhrase(*this, symbolBind, tp); diff --git a/contrib/other-builds/moses2/Vector.h b/contrib/other-builds/moses2/Vector.h index 1dbb6fec1..d32d63a11 100644 --- a/contrib/other-builds/moses2/Vector.h +++ b/contrib/other-builds/moses2/Vector.h @@ -24,6 +24,11 @@ public: { } + Vector(const Vector ©) : + Parent(copy) + { + } + protected: };