diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 2d25ecffa..f5d2d72eb 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -64,9 +64,9 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { clock_t start, end; double elapsed = 0; const MSList *friends = NULL; - FILE *infile; - char *buffer; - long numbytes; + FILE *infile = NULL; + char *buffer = NULL; + long numbytes = 0; start = clock(); linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath); @@ -82,17 +82,21 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { #endif lfl = linphone_core_create_friend_list(manager->lc); - infile = fopen(import_filepath, "r"); - fseek(infile, 0L, SEEK_END); - numbytes = ftell(infile); - fseek(infile, 0L, SEEK_SET); - buffer = (char*)ms_malloc(numbytes * sizeof(char)); - numbytes = fread(buffer, sizeof(char), numbytes, infile); - fclose(infile); + infile = fopen(import_filepath, "rb"); + BC_ASSERT_PTR_NOT_NULL(infile); + if (infile) { + fseek(infile, 0L, SEEK_END); + numbytes = ftell(infile); + fseek(infile, 0L, SEEK_SET); + buffer = (char*)ms_malloc(numbytes * sizeof(char)); + numbytes = fread(buffer, sizeof(char), numbytes, infile); + fclose(infile); - start = clock(); - linphone_friend_list_import_friends_from_vcard4_buffer(lfl, buffer); - end = clock(); + start = clock(); + linphone_friend_list_import_friends_from_vcard4_buffer(lfl, buffer); + end = clock(); + ms_free(buffer); + } friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 482, int, "%i"); // Thousand vcards contains 482 contacts with a SIP URI @@ -103,7 +107,6 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { BC_ASSERT_TRUE(elapsed < 1500000); // 1.5 seconds #endif - ms_free(buffer); linphone_friend_list_unref(lfl); ms_free(import_filepath);