From 721b34f1bd2312655b70c2f2c1536dbb14fafa46 Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Fri, 29 Jan 2016 00:30:38 +0800 Subject: [PATCH] fix bug, see details in ChangeLog.md --- ChangeLog.md | 5 +++++ include/cppjieba/HMMSegment.hpp | 4 ++-- include/cppjieba/MPSegment.hpp | 5 ++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index afe8a01..e1ca304 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,10 @@ # CppJieba ChangeLog +## next version + ++ 使用 valgrind 检查内存泄露的问题,定位出一个HMM模型初始化的问题导致内存泄露的bug,不过此内存泄露不是致命问题, +因为只会在词典载入的时候发生,而词典载入通常情况下只会被运行一次,故不会导致致命问题。 + ## v4.4.0 + 加代码容易删代码难,思索良久,还是决定把 Server 功能的源码剥离出这个项目。 diff --git a/include/cppjieba/HMMSegment.hpp b/include/cppjieba/HMMSegment.hpp index d27d0a7..7467f0d 100644 --- a/include/cppjieba/HMMSegment.hpp +++ b/include/cppjieba/HMMSegment.hpp @@ -11,8 +11,8 @@ namespace cppjieba { class HMMSegment: public SegmentBase { public: - HMMSegment(const string& filePath) { - model_ = new HMMModel(filePath); + HMMSegment(const string& filePath) + : model_(new HMMModel(filePath)), isNeedDestroy_(true) { } HMMSegment(const HMMModel* model) : model_(model), isNeedDestroy_(false) { diff --git a/include/cppjieba/MPSegment.hpp b/include/cppjieba/MPSegment.hpp index b137e00..a9d2100 100644 --- a/include/cppjieba/MPSegment.hpp +++ b/include/cppjieba/MPSegment.hpp @@ -12,9 +12,8 @@ namespace cppjieba { class MPSegment: public SegmentBase { public: - MPSegment(const string& dictPath, const string& userDictPath = "") { - dictTrie_ = new DictTrie(dictPath, userDictPath); - isNeedDestroy_ = true; + MPSegment(const string& dictPath, const string& userDictPath = "") + : dictTrie_(new DictTrie(dictPath, userDictPath)), isNeedDestroy_(true) { } MPSegment(const DictTrie* dictTrie) : dictTrie_(dictTrie), isNeedDestroy_(false) {