diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-07 20:01:09 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-07 20:01:09 +0400 |
commit | 9cd8e0ce5fae6a2f2f07908d98729a1984678c92 (patch) | |
tree | cbea9a5347550073c8a7518fc10acf52ca7f1014 /scripts/ems | |
parent | 355f8714571cfd337d5b18bafa977642cbb64e5d (diff) |
Fix memory leak: free allocated memories that were not freed.
Diffstat (limited to 'scripts/ems')
-rw-r--r-- | scripts/ems/biconcor/SuffixArray.cpp | 32 | ||||
-rw-r--r-- | scripts/ems/biconcor/SuffixArray.h | 1 |
2 files changed, 27 insertions, 6 deletions
diff --git a/scripts/ems/biconcor/SuffixArray.cpp b/scripts/ems/biconcor/SuffixArray.cpp index 4e8685f6e..f9425abe0 100644 --- a/scripts/ems/biconcor/SuffixArray.cpp +++ b/scripts/ems/biconcor/SuffixArray.cpp @@ -13,6 +13,26 @@ const int LINE_MAX_LENGTH = 10000; using namespace std; +SuffixArray::SuffixArray() + : m_array(NULL), + m_index(NULL), + m_buffer(NULL), + m_wordInSentence(NULL), + m_sentence(NULL), + m_sentenceLength(NULL), + m_vcb(), + m_size(0), + m_sentenceCount(0) { } + +SuffixArray::~SuffixArray() +{ + free(m_array); + free(m_index); + free(m_wordInSentence); + free(m_sentence); + free(m_sentenceLength); +} + void SuffixArray::Create(const string& fileName ) { m_vcb.StoreIfNew( "<uNk>" ); @@ -124,12 +144,6 @@ void SuffixArray::Sort(INDEX start, INDEX end) ((char*)m_buffer), sizeof( INDEX ) * (end-start+1) ); } -SuffixArray::~SuffixArray() -{ - free(m_index); - free(m_array); -} - int SuffixArray::CompareIndex( INDEX a, INDEX b ) const { // skip over identical words @@ -323,6 +337,12 @@ void SuffixArray::Load(const string& fileName ) fread( &m_sentenceCount, sizeof(INDEX), 1, pFile ); cerr << "sentences in corpus: " << m_sentenceCount << endl; m_sentenceLength = (char*) calloc( sizeof( char ), m_sentenceCount ); + + if (m_sentenceLength == NULL) { + cerr << "Error: cannot allocate memory to m_sentenceLength" << endl; + exit(1); + } + fread( m_sentenceLength, sizeof(char), m_sentenceCount, pFile); // sentence length fclose( pFile ); diff --git a/scripts/ems/biconcor/SuffixArray.h b/scripts/ems/biconcor/SuffixArray.h index 0bf064796..6ac77baa4 100644 --- a/scripts/ems/biconcor/SuffixArray.h +++ b/scripts/ems/biconcor/SuffixArray.h @@ -20,6 +20,7 @@ private: INDEX m_sentenceCount; public: + SuffixArray(); ~SuffixArray(); void Create(const std::string& fileName ); |