From 6793fb9635d7f6d1c8613e0e0bffc1aa609c80e4 Mon Sep 17 00:00:00 2001 From: Lane Schwartz Date: Fri, 30 Mar 2012 16:28:22 -0400 Subject: [PATCH] Fixed memory leaks when using syntactic language model. --- moses/src/SyntacticLanguageModel.cpp | 14 ++++++-------- moses/src/SyntacticLanguageModelFiles.h | 4 ++-- moses/src/SyntacticLanguageModelState.h | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/moses/src/SyntacticLanguageModel.cpp b/moses/src/SyntacticLanguageModel.cpp index 80802a568..12ade1ff7 100644 --- a/moses/src/SyntacticLanguageModel.cpp +++ b/moses/src/SyntacticLanguageModel.cpp @@ -29,7 +29,7 @@ namespace Moses SyntacticLanguageModel::~SyntacticLanguageModel() { VERBOSE(3,"Destructing SyntacticLanguageModel" << std::endl); - // delete m_files; + delete m_files; } size_t SyntacticLanguageModel::GetNumScoreComponents() const { @@ -86,10 +86,7 @@ namespace Moses VERBOSE(3,"Evaluating SyntacticLanguageModel for a hypothesis" << endl); - const SyntacticLanguageModelState& prev = - static_cast&>(*prev_state); - - const SyntacticLanguageModelState* currentState = &prev; + SyntacticLanguageModelState* tmpState = NULL; SyntacticLanguageModelState* nextState = NULL; @@ -103,10 +100,11 @@ namespace Moses const std::string& string = factor->GetString(); if (i==0) { - nextState = new SyntacticLanguageModelState(&prev, string); + nextState = new SyntacticLanguageModelState((const SyntacticLanguageModelState*)prev_state, string); } else { - currentState = nextState; - nextState = new SyntacticLanguageModelState(currentState, string); + tmpState = nextState; + nextState = new SyntacticLanguageModelState(tmpState, string); + delete tmpState; } double score = nextState->getScore(); diff --git a/moses/src/SyntacticLanguageModelFiles.h b/moses/src/SyntacticLanguageModelFiles.h index d0da9fc88..2e12e88c6 100644 --- a/moses/src/SyntacticLanguageModelFiles.h +++ b/moses/src/SyntacticLanguageModelFiles.h @@ -69,8 +69,8 @@ template SyntacticLanguageModelFiles::~SyntacticLanguageModelFiles() { VERBOSE(3,"Destructing syntactic language model files" << std::endl); - //delete hiddenModel; - //delete observedModel; + delete hiddenModel; + delete observedModel; } diff --git a/moses/src/SyntacticLanguageModelState.h b/moses/src/SyntacticLanguageModelState.h index 1be4e03b8..1c7d0dcd8 100644 --- a/moses/src/SyntacticLanguageModelState.h +++ b/moses/src/SyntacticLanguageModelState.h @@ -27,7 +27,7 @@ template