From 4766316935589b6191e047ad697ab10ae2027a43 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Wed, 8 Mar 2017 10:13:36 -0800 Subject: [PATCH] eina: force copy of not copied virtualized file while doing an eina_file_dup. The other way around is pretty much impossible as you don't know who does an eina_file_dup and for how long they keep there reference. T5234 --- src/lib/eina/eina_file_common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index b47cad72e3..cd842a7572 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -477,6 +477,19 @@ eina_file_dup(const Eina_File *f) { EINA_FILE_MAGIC_CHECK(f, NULL); eina_lock_take(&file->lock); + if (file->virtual) + { + // For ease of use and safety of the API, if you dup a virtualized file, we prefer to make a copy + if (file->global_map != (void*)(file->filename + strlen(file->filename) + 1)) + { + Eina_File *r; + + r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE); + eina_lock_release(&file->lock); + + return r; + } + } file->refcount++; eina_lock_release(&file->lock); }