summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-06-18 10:53:04 +0800
committerPeng Wu <alexepico@gmail.com>2013-06-18 11:04:29 +0800
commit17221a12d28de70bf2d0071f2359a4b13668dfc5 (patch)
tree3c2b6d4b4855609911997ad322138754a7eb8fb8 /src
parent0af289161d8498a0697132953b01b3ee2a340579 (diff)
downloadlibpinyin-17221a12d28de70bf2d0071f2359a4b13668dfc5.tar.gz
libpinyin-17221a12d28de70bf2d0071f2359a4b13668dfc5.tar.xz
libpinyin-17221a12d28de70bf2d0071f2359a4b13668dfc5.zip
fixes berkeley db calls
Diffstat (limited to 'src')
-rw-r--r--src/storage/flexible_ngram.h8
-rw-r--r--src/storage/ngram.cpp18
2 files changed, 25 insertions, 1 deletions
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h
index db4436f..6cff7ff 100644
--- a/src/storage/flexible_ngram.h
+++ b/src/storage/flexible_ngram.h
@@ -541,6 +541,7 @@ public:
*/
bool get_all_items(GArray * items){
g_array_set_size(items, 0);
+
if ( !m_db )
return false;
@@ -551,6 +552,9 @@ public:
/* Get a cursor */
m_db->cursor(m_db, NULL, &cursorp, 0);
+ if (NULL == cursorp)
+ return false;
+
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
@@ -567,6 +571,10 @@ public:
if ( ret != DB_NOTFOUND ){
fprintf(stderr, "training db error, exit!");
+
+ if (cursorp != NULL)
+ cursorp->c_close(cursorp);
+
exit(EIO);
}
diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp
index 7509b17..3964388 100644
--- a/src/storage/ngram.cpp
+++ b/src/storage/ngram.cpp
@@ -287,6 +287,9 @@ bool Bigram::load_db(const char * dbfile){
ret = db_create(&tmp_db, NULL, 0);
assert(ret == 0);
+ if (NULL == tmp_db)
+ return false;
+
ret = tmp_db->open(tmp_db, NULL, dbfile, NULL,
DB_HASH, DB_RDONLY, 0600);
if ( ret != 0 )
@@ -294,9 +297,13 @@ bool Bigram::load_db(const char * dbfile){
DBC * cursorp = NULL;
DBT key, data;
+
/* Get a cursor */
tmp_db->cursor(tmp_db, NULL, &cursorp, 0);
+ if (NULL == cursorp)
+ return false;
+
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
@@ -328,6 +335,9 @@ bool Bigram::save_db(const char * dbfile){
ret = db_create(&tmp_db, NULL, 0);
assert(ret == 0);
+ if (NULL == tmp_db)
+ return false;
+
ret = tmp_db->open(tmp_db, NULL, dbfile, NULL,
DB_HASH, DB_CREATE, 0600);
if ( ret != 0 )
@@ -338,6 +348,9 @@ bool Bigram::save_db(const char * dbfile){
/* Get a cursor */
m_db->cursor(m_db, NULL, &cursorp, 0);
+ if (NULL == cursorp)
+ return false;
+
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
@@ -444,7 +457,10 @@ bool Bigram::get_all_items(GArray * items){
DBT key, data;
int ret;
/* Get a cursor */
- m_db->cursor(m_db, NULL, &cursorp, 0);
+ m_db->cursor(m_db, NULL, &cursorp, 0);
+
+ if (NULL == cursorp)
+ return false;
/* Initialize our DBTs. */
memset(&key, 0, sizeof(DBT));