evas/cserve2: Fix crash in server when an image file changes
authorJean-Philippe Andre <jp.andre@samsung.com>
Tue, 29 Oct 2013 10:45:13 +0000 (19:45 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Wed, 30 Oct 2013 10:48:17 +0000 (19:48 +0900)
Since cserve2 uses inotify to track image file updates,
it will drop its references to a specific file and all
the associated images.
Fix some logic in the deletion code.

src/bin/evas/evas_cserve2_cache.c

index 4c20a72..4322be2 100644 (file)
@@ -1075,9 +1075,12 @@ _image_entry_free(Image_Entry *ientry)
    if (fd)
      {
         fentry = _file_entry_find(fd->id);
-        fentry->images = eina_list_remove(fentry->images, ientry);
-        if (fentry && !fentry->images && !ASENTRY(fentry)->references)
-          eina_hash_del_by_key(file_entries, &fd->id);
+        if (fentry)
+          {
+             fentry->images = eina_list_remove(fentry->images, ientry);
+             if (!fentry->images && !ASENTRY(fentry)->references)
+               eina_hash_del_by_key(file_entries, &fd->id);
+          }
      }
    else
       ERR("Could not find file data %u for image %u",
@@ -1669,18 +1672,14 @@ static void
 _file_changed_cb(const char *path EINA_UNUSED, Eina_Bool deleted EINA_UNUSED, void *data)
 {
    File_Watch *fw = data;
-   File_Data *fd;
+   File_Entry *fentry;
    Eina_List *l;
 
-   EINA_LIST_FOREACH(fw->entries, l, fd)
+   EINA_LIST_FOREACH(fw->entries, l, fentry)
      {
         Eina_List *ll;
         Image_Entry *ie;
-        File_Entry *fentry;
-
-        fd->invalid = EINA_TRUE;
-        fentry = _file_entry_find(fd->id);
-        if (!fentry) continue;
+        File_Data *fd;
 
         fentry->watcher = NULL;
 
@@ -1688,13 +1687,13 @@ _file_changed_cb(const char *path EINA_UNUSED, Eina_Bool deleted EINA_UNUSED, vo
           {
              Image_Data *idata;
 
+             idata = _image_data_find(ENTRYID(ie));
              eina_hash_set(image_entries, &ENTRYID(ie), NULL);
              if (ASENTRY(ie)->request /*&& !ie->base.request->processing*/)
                cserve2_request_cancel_all(ASENTRY(ie)->request,
                                           CSERVE2_FILE_CHANGED);
              ASENTRY(ie)->request = NULL;
 
-             idata = _image_data_find(ENTRYID(ie));
              if (idata)
                {
                   _image_id_free(idata);
@@ -1703,8 +1702,15 @@ _file_changed_cb(const char *path EINA_UNUSED, Eina_Bool deleted EINA_UNUSED, vo
                }
           }
 
-        _file_id_free(fd);
-        eina_hash_set(file_entries, &fd->id, NULL);
+
+        fd = _file_data_find(ENTRYID(fentry));
+        if (fd)
+          {
+             fd->invalid = EINA_TRUE;
+             _file_id_free(fd);
+             eina_hash_set(file_entries, &fd->id, NULL);
+          }
+
         if (ASENTRY(fentry)->request
             /*&& !ASENTRY(fentry)->request->processing*/)
           {