From 0d9eed4ef1c509e0518ffe3154791a1b36899bea Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 21 Dec 2015 17:20:09 +0100 Subject: [PATCH] Fix segfault + uses new singleton to parse friends from database much faster --- coreapi/friend.c | 9 +++++---- coreapi/vcard.cc | 15 ++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index ba6d27ced..ac2ad9970 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -858,13 +858,14 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char * LinphoneVCard *vcard = (LinphoneVCard *)vcards->data; LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard); if (lf) { - linphone_friend_list_import_friend(lc->friendlist, lf); - lf->lc = lc; + if (LinphoneFriendListOK == linphone_friend_list_import_friend(lc->friendlist, lf)) { + lf->lc = lc; #ifdef FRIENDS_SQL_STORAGE_ENABLED - linphone_core_store_friend_in_db(lc, lf); + linphone_core_store_friend_in_db(lc, lf); #endif + count++; + } linphone_friend_unref(lf); - count++; } vcards = ms_list_next(vcards); } diff --git a/coreapi/vcard.cc b/coreapi/vcard.cc index c50043e03..0ecff260c 100644 --- a/coreapi/vcard.cc +++ b/coreapi/vcard.cc @@ -41,8 +41,8 @@ extern "C" void linphone_vcard_free(LinphoneVCard *vCard) { extern "C" MSList* linphone_vcard_list_from_vcard4_file(const char *filename) { MSList *result = NULL; if (filename && ortp_file_exist(filename) == 0) { - belcard::BelCardParser *parser = new belcard::BelCardParser(); - shared_ptr belCards = parser->parseFile(filename); + belcard::BelCardParser parser = belcard::BelCardParser::getInstance(); + shared_ptr belCards = parser.parseFile(filename); if (belCards) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { shared_ptr belcard = (*it); @@ -51,7 +51,6 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_file(const char *filename) { result = ms_list_append(result, vCard); } } - delete parser; } return result; } @@ -59,8 +58,8 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_file(const char *filename) { extern "C" MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) { MSList *result = NULL; if (buffer) { - belcard::BelCardParser *parser = new belcard::BelCardParser(); - shared_ptr belCards = parser->parse(buffer); + belcard::BelCardParser parser = belcard::BelCardParser::getInstance(); + shared_ptr belCards = parser.parse(buffer); if (belCards) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { shared_ptr belCard = (*it); @@ -69,7 +68,6 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) { result = ms_list_append(result, vCard); } } - delete parser; } return result; } @@ -77,13 +75,12 @@ extern "C" MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) { extern "C" LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buffer) { LinphoneVCard *vCard = NULL; if (buffer) { - belcard::BelCardParser *parser = new belcard::BelCardParser(); - shared_ptr belCard = parser->parseOne(buffer); + belcard::BelCardParser parser = belcard::BelCardParser::getInstance(); + shared_ptr belCard = parser.parseOne(buffer); if (belCard) { vCard = linphone_vcard_new(); vCard->belCard = belCard; } - delete parser; } return vCard; }