From 621fb3be0bfe55d914e36f550b7b344747ad9855 Mon Sep 17 00:00:00 2001 From: Stephen okra Houston Date: Mon, 28 Nov 2016 10:30:29 -0600 Subject: [PATCH] Ephoto: Fix coverity issues: CID 151524, 151521, 151520, 151518, 151517, 151516, 151515, 151512 --- src/bin/ephoto_directory_browser.c | 22 ++++--- src/bin/ephoto_file.c | 94 ++++++++++++++++++------------ src/bin/ephoto_main.c | 5 +- 3 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/bin/ephoto_directory_browser.c b/src/bin/ephoto_directory_browser.c index d1d60d7..75c6c3d 100644 --- a/src/bin/ephoto_directory_browser.c +++ b/src/bin/ephoto_directory_browser.c @@ -1168,13 +1168,10 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto) dir = ecore_file_dir_get(path); dirs = eina_list_prepend(dirs, strdup(dir)); memset(path, 0x00, sizeof(path)); - snprintf(path, PATH_MAX, "%s", dir); - } - if (dir) - { - free(dir); - dir = NULL; + snprintf(path, PATH_MAX, "%s", dir); } + free(dir); + dir = NULL; } } EINA_LIST_FOREACH(dirs, l, dir) @@ -1224,13 +1221,13 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto) { _monitor_add(entry); entry->genlist = db->fsel; - } - if (n) - { - if (!strcmp(n, entry->path)) + if (n) { - next = entry->item; - elm_genlist_item_expanded_set(next, EINA_TRUE); + if (!strcmp(n, entry->path)) + { + next = entry->item; + elm_genlist_item_expanded_set(next, EINA_TRUE); + } } } } @@ -1253,6 +1250,7 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto) } ephoto_title_set(ephoto, ephoto->config->directory); db->initializing = EINA_FALSE; + free(end_dir); } Evas_Object * diff --git a/src/bin/ephoto_file.c b/src/bin/ephoto_file.c index 551c095..acf4238 100644 --- a/src/bin/ephoto_file.c +++ b/src/bin/ephoto_file.c @@ -744,38 +744,40 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED) int ret; struct stat s; - lstat(file, &s); - if (S_ISLNK(s.st_mode)) + if (lstat(file, &s)) { - ret = ecore_file_unlink(file); - } - else - { - snprintf(fp, PATH_MAX, "%s", file); - snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp)); - if (ecore_file_exists(dest)) - { - snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination, - basename(fp)); - if (ecore_file_exists(extra)) - { - int count; - - for (count = 2; ecore_file_exists(extra); count++) - { - memset(extra, 0, sizeof(extra)); - snprintf(extra, PATH_MAX, "%s/Copy%dOf%s", - destination, count, basename(fp)); - } - } - ret = ecore_file_mv(file, extra); - } + if (S_ISLNK(s.st_mode)) + { + ret = ecore_file_unlink(file); + } else - ret = ecore_file_mv(file, dest); - } - if (!ret) - ephoto->file_errors++; - } + { + snprintf(fp, PATH_MAX, "%s", file); + snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp)); + if (ecore_file_exists(dest)) + { + snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination, + basename(fp)); + if (ecore_file_exists(extra)) + { + int count; + + for (count = 2; ecore_file_exists(extra); count++) + { + memset(extra, 0, sizeof(extra)); + snprintf(extra, PATH_MAX, "%s/Copy%dOf%s", + destination, count, basename(fp)); + } + } + ret = ecore_file_mv(file, extra); + } + else + ret = ecore_file_mv(file, dest); + } + if (!ret) + ephoto->file_errors++; + } + } } } @@ -919,11 +921,21 @@ _prompt_upload_apply(void *data, Evas_Object *obj EINA_UNUSED, evas_object_show(popup); f = fopen(entry->path, "rb"); - if (!f) CRIT("unable to open '%s': %s", entry->path, strerror(errno)); + if (!f) + { + CRIT("unable to open '%s': %s", entry->path, strerror(errno)); + evas_object_del(popup); + return; + } res = fseek(f, 0, SEEK_END); if (!res) CRIT("fseek() failed on file '%s': %s", entry->path, strerror(errno)); fsize = ftell(f); - if (fsize == -1) CRIT("ftell() failed on file '%s': %s", entry->path, strerror(errno)); + if (fsize == -1) + { + CRIT("ftell() failed on file '%s': %s", entry->path, strerror(errno)); + evas_object_del(popup); + return; + } rewind(f); fdata = malloc(fsize); res = fread(fdata, fsize, 1, f); @@ -1007,16 +1019,22 @@ _prompt_save_image_as_apply(void *data, Evas_Object *obj, void *event_info) else { ext = eina_stringshare_add((strrchr(selected, '.')+1)); - if (!_ephoto_file_image_can_save(ext)) + if (ext) { - if (ext) - eina_stringshare_del(ext); - snprintf(buf, PATH_MAX, "%s.jpg", selected); + if (!_ephoto_file_image_can_save(ext)) + { + eina_stringshare_del(ext); + snprintf(buf, PATH_MAX, "%s.jpg", selected); + } + else + { + eina_stringshare_del(ext); + snprintf(buf, PATH_MAX, "%s", selected); + } } else { - if (ext) - eina_stringshare_del(ext); + eina_stringshare_del(ext); snprintf(buf, PATH_MAX, "%s", selected); } } diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index c592722..274616b 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -995,7 +995,10 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded, ed->thumbs_only = thumbs_only; if (!ecore_file_can_read(path)) - return; + { + free(ed); + return; + } EINA_LIST_FREE(ed->ephoto->thumbs, o) evas_object_del(o);