eio: fix memory leak when using file associate.
authorCedric BAIL <cedric.bail@free.fr>
Thu, 30 Aug 2012 08:52:15 +0000 (08:52 +0000)
committerCedric BAIL <cedric.bail@free.fr>
Thu, 30 Aug 2012 08:52:15 +0000 (08:52 +0000)
SVN revision: 75854

legacy/eio/ChangeLog
legacy/eio/NEWS
legacy/eio/src/lib/eio_dir.c
legacy/eio/src/lib/eio_file.c
legacy/eio/src/lib/eio_private.h
legacy/eio/src/lib/eio_single.c
legacy/eio/src/lib/eio_xattr.c

index 90cccb3..dfa4c95 100644 (file)
@@ -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.
index 81e5918..5da27bd 100644 (file)
@@ -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
index 40d2b6a..5de5fb6 100644 (file)
@@ -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(&copy->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);
 }
 
 /**
index f1a5579..247546f 100644 (file)
@@ -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(&copy->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
@@ -703,14 +703,20 @@ eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
 }
 
 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__)
 {
    Eio_File_Ls *async = data;
 
    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);
 }
 
 /**
index aab69dc..ef983f9 100644 (file)
@@ -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);
index 69f4185..8bc99fa 100644 (file)
@@ -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.
index 6960284..cff21b9 100644 (file)
@@ -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