fixes memory leak
This commit is contained in:
parent
42d213c0be
commit
a5c163cf4d
@ -1,7 +1,7 @@
|
||||
From 127a5ce640ec5282bbb4b473c01c5366e3c5e2f2 Mon Sep 17 00:00:00 2001
|
||||
From: Peng Wu <alexepico@gmail.com>
|
||||
Date: Tue, 11 Oct 2011 14:56:23 +0800
|
||||
Subject: [PATCH 1/3] fixes fsf address
|
||||
Subject: [PATCH 1/4] fixes fsf address
|
||||
|
||||
---
|
||||
src/include/memory_chunk.h | 2 +-
|
||||
@ -769,7 +769,7 @@ index 5fc7031..b9b864c 100644
|
||||
From 6df832baaa4c06bcffed93620edf5431ee9249fc Mon Sep 17 00:00:00 2001
|
||||
From: Peng Wu <alexepico@gmail.com>
|
||||
Date: Wed, 26 Oct 2011 10:22:44 +0800
|
||||
Subject: [PATCH 2/3] add m_modified
|
||||
Subject: [PATCH 2/4] add m_modified
|
||||
|
||||
---
|
||||
src/pinyin.cpp | 14 ++++++++++----
|
||||
@ -851,7 +851,7 @@ index c8eff79..46269e1 100644
|
||||
From cdd9f5355a24f59f3aa587842d5b0a7e9fce4394 Mon Sep 17 00:00:00 2001
|
||||
From: Peng Wu <alexepico@gmail.com>
|
||||
Date: Thu, 27 Oct 2011 14:37:43 +0800
|
||||
Subject: [PATCH 3/3] fixes load_db
|
||||
Subject: [PATCH 3/4] fixes load_db
|
||||
|
||||
---
|
||||
src/storage/ngram.cpp | 16 +++++++++-------
|
||||
@ -894,3 +894,124 @@ index 17c7e9b..fedd744 100644
|
||||
--
|
||||
1.7.6.4
|
||||
|
||||
|
||||
From 81ca3def70f06419f90c8db0246fad614ec9d11a Mon Sep 17 00:00:00 2001
|
||||
From: Peng Wu <alexepico@gmail.com>
|
||||
Date: Thu, 27 Oct 2011 18:05:44 +0800
|
||||
Subject: [PATCH 4/4] fixes save_db
|
||||
|
||||
---
|
||||
src/pinyin.cpp | 15 +++++++++++++++
|
||||
src/storage/ngram.cpp | 3 ++-
|
||||
2 files changed, 17 insertions(+), 1 deletions(-)
|
||||
|
||||
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
|
||||
index 46269e1..8832321 100644
|
||||
--- a/src/pinyin.cpp
|
||||
+++ b/src/pinyin.cpp
|
||||
@@ -63,6 +63,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
|
||||
fprintf(stderr, "open %s failed!\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
+ g_free(filename);
|
||||
context->m_pinyin_table->load(chunk);
|
||||
|
||||
context->m_validator.initialize(context->m_pinyin_table);
|
||||
@@ -77,6 +78,7 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
|
||||
fprintf(stderr, "open %s failed!\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
+ g_free(filename);
|
||||
context->m_phrase_table->load(chunk);
|
||||
|
||||
context->m_phrase_index = new FacadePhraseIndex;
|
||||
@@ -86,9 +88,11 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
|
||||
fprintf(stderr, "open %s failed!\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
+ g_free(filename);
|
||||
context->m_phrase_index->load(1, chunk);
|
||||
filename = g_build_filename(context->m_user_dir, "gb_char.dbin", NULL);
|
||||
log->load(filename);
|
||||
+ g_free(filename);
|
||||
context->m_phrase_index->merge(1, log);
|
||||
|
||||
log = new MemoryChunk; chunk = new MemoryChunk;
|
||||
@@ -97,17 +101,22 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
|
||||
fprintf(stderr, "open %s failed!\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
+ g_free(filename);
|
||||
context->m_phrase_index->load(2, chunk);
|
||||
filename = g_build_filename(context->m_user_dir, "gbk_char.dbin", NULL);
|
||||
log->load(filename);
|
||||
+ g_free(filename);
|
||||
context->m_phrase_index->merge(2, log);
|
||||
|
||||
context->m_system_bigram = new Bigram;
|
||||
filename = g_build_filename(context->m_system_dir, "bigram.db", NULL);
|
||||
context->m_system_bigram->attach(filename, ATTACH_READONLY);
|
||||
+ g_free(filename);
|
||||
+
|
||||
context->m_user_bigram = new Bigram;
|
||||
filename = g_build_filename(context->m_user_dir, "user.db", NULL);
|
||||
context->m_user_bigram->load_db(filename);
|
||||
+ g_free(filename);
|
||||
|
||||
context->m_pinyin_lookup = new PinyinLookup
|
||||
( &(context->m_custom), context->m_pinyin_table,
|
||||
@@ -134,24 +143,30 @@ bool pinyin_save(pinyin_context_t * context){
|
||||
gchar * filename = g_build_filename(context->m_system_dir,
|
||||
"gb_char.bin", NULL);
|
||||
oldchunk->load(filename);
|
||||
+ g_free(filename);
|
||||
context->m_phrase_index->diff(1, oldchunk, newlog);
|
||||
filename = g_build_filename(context->m_user_dir,
|
||||
"gb_char.dbin", NULL);
|
||||
newlog->save(filename);
|
||||
+ g_free(filename);
|
||||
delete newlog;
|
||||
|
||||
oldchunk = new MemoryChunk; newlog = new MemoryChunk;
|
||||
filename = g_build_filename(context->m_system_dir,
|
||||
"gbk_char.bin", NULL);
|
||||
oldchunk->load(filename);
|
||||
+ g_free(filename);
|
||||
+
|
||||
context->m_phrase_index->diff(2, oldchunk, newlog);
|
||||
filename = g_build_filename(context->m_user_dir,
|
||||
"gbk_char.dbin", NULL);
|
||||
newlog->save(filename);
|
||||
+ g_free(filename);
|
||||
delete newlog;
|
||||
|
||||
filename = g_build_filename(context->m_user_dir, "user.db", NULL);
|
||||
context->m_user_bigram->save_db(filename);
|
||||
+ g_free(filename);
|
||||
|
||||
context->m_modified = false;
|
||||
return true;
|
||||
diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp
|
||||
index fedd744..f7dd347 100644
|
||||
--- a/src/storage/ngram.cpp
|
||||
+++ b/src/storage/ngram.cpp
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
+#include <errno.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include "memory_chunk.h"
|
||||
@@ -273,7 +274,7 @@ bool Bigram::save_db(const char * dbfile){
|
||||
DB * tmp_db = NULL;
|
||||
|
||||
int ret = g_unlink(dbfile);
|
||||
- if ( ret != 0 )
|
||||
+ if ( ret != 0 && errno != ENOENT)
|
||||
return false;
|
||||
|
||||
ret = db_create(&tmp_db, NULL, 0);
|
||||
--
|
||||
1.7.6.4
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: libpinyin
|
||||
Version: 0.2.99.2
|
||||
Release: 4%{?dist}
|
||||
Release: 5%{?dist}
|
||||
Summary: Library to deal with pinyin
|
||||
|
||||
License: GPLv2+
|
||||
@ -70,6 +70,9 @@ find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
|
||||
%{_datadir}/libpinyin/data
|
||||
|
||||
%changelog
|
||||
* Mon Oct 31 2011 Peng Wu <pwu@redhat.com> - 0.2.99.2-5
|
||||
- Fixes memory leak and save_db
|
||||
|
||||
* Thu Oct 27 2011 Peng Wu <pwu@redhat.com> - 0.2.99.2-4
|
||||
- Update libpinyin-0.3.x-head.patch
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user