summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-11-20 10:19:16 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-20 10:22:00 +0100
commit58b578c9b07497496fedd51f3aa3bd434a0fa305 (patch)
tree00840be00995dfdd3b3595d32350ec5f1aae43c2
parent8a3e021298c8d7ebf8cb587554422aa6a93edcc9 (diff)
eina: fix a possible race condition during eina_file_close.
replay 7e8fb93 without the breakage
-rw-r--r--ChangeLog4
-rw-r--r--NEWS3
-rw-r--r--src/lib/eina/eina_file_common.c9
-rw-r--r--src/tests/eina/eina_test_file.c34
4 files changed, 46 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 3dc7c28258..6c3dea3a93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12013-11-20 Cedric Bail
2
3 * Eina: Fix a possible race condition during eina_file_close.
4
12013-11-19 Tom Hacohen 52013-11-19 Tom Hacohen
2 6
3 * Evas textblock: Fixed order of tags inserted with markup_app/prepend. 7 * Evas textblock: Fixed order of tags inserted with markup_app/prepend.
diff --git a/NEWS b/NEWS
index 6a1f8bdb01..5ce9bcf17b 100644
--- a/NEWS
+++ b/NEWS
@@ -268,7 +268,8 @@ Fixes:
268 - Fix memory leak in eina_xattr_value_ls. 268 - Fix memory leak in eina_xattr_value_ls.
269 - Fix magic failure in eina_value_array_count when array has not been allocated. 269 - Fix magic failure in eina_value_array_count when array has not been allocated.
270 - Fix issue when wchar_t is signed and eina_unicode does negative array lookups. 270 - Fix issue when wchar_t is signed and eina_unicode does negative array lookups.
271 - Eina: fix eina_file_map_lines() to not drop of one character in the last line. 271 - Fix eina_file_map_lines() to not drop of one character in the last line.
272 - Fix a possible race condition during eina_file_close().
272 * Eet: 273 * Eet:
273 - Fix PPC (big endian) image codec bug. 274 - Fix PPC (big endian) image codec bug.
274 - Fix leak in eet_pbkdf2_sha1 with OpenSSL. 275 - Fix leak in eet_pbkdf2_sha1 with OpenSSL.
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index 7b05b3b249..7f83c87774 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -451,17 +451,20 @@ eina_file_close(Eina_File *file)
451 451
452 EINA_SAFETY_ON_NULL_RETURN(file); 452 EINA_SAFETY_ON_NULL_RETURN(file);
453 453
454 eina_lock_take(&_eina_file_lock_cache);
455
454 eina_lock_take(&file->lock); 456 eina_lock_take(&file->lock);
455 file->refcount--; 457 file->refcount--;
456 if (file->refcount == 0) leave = EINA_FALSE; 458 if (file->refcount == 0) leave = EINA_FALSE;
457 eina_lock_release(&file->lock); 459 eina_lock_release(&file->lock);
458 if (leave) return; 460 if (leave) goto end;
459
460 eina_lock_take(&_eina_file_lock_cache);
461 461
462 eina_hash_del(_eina_file_cache, file->filename, file); 462 eina_hash_del(_eina_file_cache, file->filename, file);
463
464 // Backend specific file resource close
463 eina_file_real_close(file); 465 eina_file_real_close(file);
464 466
467 end:
465 eina_lock_release(&_eina_file_lock_cache); 468 eina_lock_release(&_eina_file_lock_cache);
466} 469}
467 470
diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c
index f2f322550f..e8f735d3f0 100644
--- a/src/tests/eina/eina_test_file.c
+++ b/src/tests/eina/eina_test_file.c
@@ -441,6 +441,39 @@ START_TEST(eina_test_file_virtualize)
441} 441}
442END_TEST 442END_TEST
443 443
444static void *
445_eina_test_file_thread(void *data EINA_UNUSED, Eina_Thread t EINA_UNUSED)
446{
447 Eina_File *f;
448 unsigned int i;
449
450 for (i = 0; i < 10000; ++i)
451 {
452 f = eina_file_open("/bin/sh", EINA_FALSE);
453 fail_if(!f);
454 eina_file_close(f);
455 }
456
457 return NULL;
458}
459
460START_TEST(eina_test_file_thread)
461{
462 Eina_Thread th[4];
463 unsigned int i;
464
465 fail_if(!eina_init());
466
467 for (i = 0; i < 4; i++)
468 fail_if(!(eina_thread_create(&th[i], EINA_THREAD_NORMAL, 0, _eina_test_file_thread, NULL)));
469
470 for (i = 0; i < 4; i++)
471 fail_if(eina_thread_join(th[i]) != NULL);
472
473 eina_shutdown();
474}
475END_TEST
476
444void 477void
445eina_test_file(TCase *tc) 478eina_test_file(TCase *tc)
446{ 479{
@@ -449,5 +482,6 @@ eina_test_file(TCase *tc)
449 tcase_add_test(tc, eina_file_ls_simple); 482 tcase_add_test(tc, eina_file_ls_simple);
450 tcase_add_test(tc, eina_file_map_new_test); 483 tcase_add_test(tc, eina_file_map_new_test);
451 tcase_add_test(tc, eina_test_file_virtualize); 484 tcase_add_test(tc, eina_test_file_virtualize);
485 tcase_add_test(tc, eina_test_file_thread);
452} 486}
453 487