From f82152f150560edfa555f88ece77e5f7bf0ece06 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 30 Aug 2012 08:52:15 +0000 Subject: [PATCH] eio: fix memory leak when using file associate. SVN revision: 75854 --- legacy/eio/ChangeLog | 4 ++++ legacy/eio/NEWS | 1 + legacy/eio/src/lib/eio_dir.c | 8 +++----- legacy/eio/src/lib/eio_file.c | 17 +++++++++++------ legacy/eio/src/lib/eio_private.h | 3 +++ legacy/eio/src/lib/eio_single.c | 20 ++++++++++++++++---- legacy/eio/src/lib/eio_xattr.c | 2 +- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/legacy/eio/ChangeLog b/legacy/eio/ChangeLog index 90cccb3724..dfa4c95684 100644 --- a/legacy/eio/ChangeLog +++ b/legacy/eio/ChangeLog @@ -27,3 +27,7 @@ * Do not free Windows stuff when it is not used. Fix seg fault * Add log debugging macros + +2012-08-30 Cedric Bail + + * Fix memory leak when using file associate API. diff --git a/legacy/eio/NEWS b/legacy/eio/NEWS index 81e59189d8..5da27bd815 100644 --- a/legacy/eio/NEWS +++ b/legacy/eio/NEWS @@ -11,6 +11,7 @@ Fixes: - memory leak when shutting down fallback monitor. - properly shutdown monitor. - Fix segfault when shutting down the Windows monitor. + - Fix memory leak when using file_associate. Improvements: - Add log debuggong macros diff --git a/legacy/eio/src/lib/eio_dir.c b/legacy/eio/src/lib/eio_dir.c index 40d2b6a670..5de5fb661b 100644 --- a/legacy/eio/src/lib/eio_dir.c +++ b/legacy/eio/src/lib/eio_dir.c @@ -454,7 +454,7 @@ _eio_dir_copy_free(Eio_Dir_Copy *copy) { eina_stringshare_del(copy->progress.source); eina_stringshare_del(copy->progress.dest); - free(copy); + eio_file_free(©->progress.common); } static void @@ -777,8 +777,7 @@ _eio_dir_stat_done(void *data, Ecore_Thread *thread __UNUSED__) async->common.done_cb((void*) async->common.data, &async->common); - eina_stringshare_del(async->directory); - free(async); + eio_async_free(async); } static void @@ -788,8 +787,7 @@ _eio_dir_stat_error(void *data, Ecore_Thread *thread __UNUSED__) eio_file_error(&async->common); - eina_stringshare_del(async->directory); - free(async); + eio_async_free(async); } /** diff --git a/legacy/eio/src/lib/eio_file.c b/legacy/eio/src/lib/eio_file.c index f1a55794f4..247546fcd6 100644 --- a/legacy/eio/src/lib/eio_file.c +++ b/legacy/eio/src/lib/eio_file.c @@ -429,7 +429,7 @@ _eio_file_copy_free(Eio_File_Progress *copy) { eina_stringshare_del(copy->source); eina_stringshare_del(copy->dest); - free(copy); + eio_file_free(©->common); } static void @@ -457,7 +457,7 @@ _eio_file_move_free(Eio_File_Move *move) { eina_stringshare_del(move->progress.source); eina_stringshare_del(move->progress.dest); - free(move); + eio_file_free(&move->progress.common); } static void @@ -702,6 +702,13 @@ eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy) return EINA_FALSE; } +void +eio_async_free(Eio_File_Ls *async) +{ + eina_stringshare_del(async->directory); + eio_file_free(&async->common); +} + void eio_async_end(void *data, Ecore_Thread *thread __UNUSED__) { @@ -709,8 +716,7 @@ eio_async_end(void *data, Ecore_Thread *thread __UNUSED__) async->common.done_cb((void*) async->common.data, &async->common); - eina_stringshare_del(async->directory); - free(async); + eio_async_free(async); } void @@ -720,8 +726,7 @@ eio_async_error(void *data, Ecore_Thread *thread __UNUSED__) eio_file_error(&async->common); - eina_stringshare_del(async->directory); - free(async); + eio_async_free(async); } /** diff --git a/legacy/eio/src/lib/eio_private.h b/legacy/eio/src/lib/eio_private.h index aab69dc2f2..ef983f98a0 100644 --- a/legacy/eio/src/lib/eio_private.h +++ b/legacy/eio/src/lib/eio_private.h @@ -464,6 +464,9 @@ Eina_Bool eio_long_file_set(Eio_File *common, Ecore_Thread_Cb end_cb, Ecore_Thread_Cb cancel_cb); +void eio_file_free(Eio_File *common); +void eio_async_free(Eio_File_Ls *async); + void eio_file_container_set(Eio_File *common, void *container); void eio_file_error(Eio_File *common); diff --git a/legacy/eio/src/lib/eio_single.c b/legacy/eio/src/lib/eio_single.c index 69f4185c29..8bc99fa41e 100644 --- a/legacy/eio/src/lib/eio_single.c +++ b/legacy/eio/src/lib/eio_single.c @@ -42,7 +42,7 @@ static void _eio_mkdir_free(Eio_File_Mkdir *m) { eina_stringshare_del(m->path); - free(m); + eio_file_free(&m->common); } static void @@ -78,7 +78,7 @@ static void _eio_unlink_free(Eio_File_Unlink *l) { eina_stringshare_del(l->path); - free(l); + eio_file_free(&l->common); } static void @@ -169,7 +169,7 @@ static void _eio_stat_free(Eio_File_Stat *s) { eina_stringshare_del(s->path); - free(s); + eio_file_free(&s->common); } static void @@ -272,7 +272,7 @@ _eio_chown_free(Eio_File_Chown *ch) if (ch->user) eina_stringshare_del(ch->user); if (ch->group) eina_stringshare_del(ch->group); eina_stringshare_del(ch->path); - free(ch); + eio_file_free(&ch->common); } static void @@ -321,6 +321,16 @@ eio_file_thread_error(Eio_File *common, Ecore_Thread *thread) ecore_thread_cancel(thread); } +void +eio_file_free(Eio_File *common) +{ + if (common->worker.associated) + eina_hash_free(common->worker.associated); + if (common->main.associated) + eina_hash_free(common->main.associated); + free(common); +} + Eina_Bool eio_long_file_set(Eio_File *common, Eio_Done_Cb done_cb, @@ -372,6 +382,8 @@ eio_file_set(Eio_File *common, common->error = 0; common->thread = NULL; common->container = NULL; + common->worker.associated = NULL; + common->main.associated = NULL; /* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. This means that common would be destroyed if thread == NULL. diff --git a/legacy/eio/src/lib/eio_xattr.c b/legacy/eio/src/lib/eio_xattr.c index 696028446d..cff21b92e7 100644 --- a/legacy/eio/src/lib/eio_xattr.c +++ b/legacy/eio/src/lib/eio_xattr.c @@ -113,7 +113,7 @@ _eio_file_xattr_free(Eio_File_Xattr *async) if (async->op == EIO_XATTR_DATA) free(async->todo.xdata.xattr_data); if (async->op == EIO_XATTR_STRING) free(async->todo.xstring.xattr_string); } - free(async); + eio_file_free(&async->common); } static void