diff --git a/legacy/efreet/src/bin/ef_utils.c b/legacy/efreet/src/bin/ef_utils.c index f26f504bb1..80910d5a91 100644 --- a/legacy/efreet/src/bin/ef_utils.c +++ b/legacy/efreet/src/bin/ef_utils.c @@ -8,23 +8,21 @@ ef_cb_utils(void) Efreet_Desktop *desktop; char *tmp; + printf("\n"); tmp = efreet_util_path_in_default("applications", "/usr/share/applications/test.desktop"); - if (!tmp || strcmp(tmp, "/usr/share/applications")) + if (tmp) { - if (tmp) free(tmp); - return 0; + printf("%s\n", tmp); + free(tmp); } - if (tmp) free(tmp); - tmp = efreet_util_path_to_file_id("/usr/share/applications", - "/usr/share/applications/this/tmp/test.desktop"); - if (!tmp || strcmp(tmp, "this-tmp-test.desktop")) + tmp = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop"); + if (tmp) { - if (tmp) free(tmp); - return 0; + printf("%s\n", tmp); + free(tmp); } - if (tmp) free(tmp); desktop = efreet_util_desktop_by_file_id_get("kde-kresources.desktop"); printf("kde-kresources.desktop: %p\n", desktop); diff --git a/legacy/efreet/src/lib/efreet_menu.c b/legacy/efreet/src/lib/efreet_menu.c index b9033eff4f..c956750a2c 100644 --- a/legacy/efreet/src/lib/efreet_menu.c +++ b/legacy/efreet/src/lib/efreet_menu.c @@ -803,13 +803,10 @@ int efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos) { Efreet_Menu *entry; - char *path; char *id; if (!desktop || !menu) return 0; - path = efreet_util_path_in_default("applications", desktop->orig_path); - if (!path) return 0; - id = efreet_util_path_to_file_id(path, desktop->orig_path); + id = efreet_util_path_to_file_id(desktop->orig_path); entry = efreet_menu_entry_new(); entry->type = EFREET_MENU_ENTRY_DESKTOP; @@ -833,7 +830,6 @@ efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos) } free(id); - free(path); return 1; } diff --git a/legacy/efreet/src/lib/efreet_utils.c b/legacy/efreet/src/lib/efreet_utils.c index 9d5b7228e8..ff742621d2 100644 --- a/legacy/efreet/src/lib/efreet_utils.c +++ b/legacy/efreet/src/lib/efreet_utils.c @@ -41,14 +41,27 @@ efreet_util_path_in_default(const char *section, const char *path) } char * -efreet_util_path_to_file_id(const char *base, const char *path) +efreet_util_path_to_file_id(const char *path) { size_t len; char *id, *p; + char *base; + + if (!path) return NULL; + base = efreet_util_path_in_default("applications", path); + if (!base) return NULL; len = strlen(base); - if (strlen(path) <= len) return NULL; - if (strncmp(path, base, len)) return NULL; + if (strlen(path) <= len) + { + free(base); + return NULL; + } + if (strncmp(path, base, len)) + { + free(base); + return NULL; + } id = strdup(path + len + 1); p = id; @@ -57,6 +70,7 @@ efreet_util_path_to_file_id(const char *base, const char *path) if (*p == '/') *p = '-'; p++; } + free(base); return id; } diff --git a/legacy/efreet/src/lib/efreet_utils.h b/legacy/efreet/src/lib/efreet_utils.h index 0c790d0157..51847d695e 100644 --- a/legacy/efreet/src/lib/efreet_utils.h +++ b/legacy/efreet/src/lib/efreet_utils.h @@ -3,7 +3,7 @@ #define EFREET_UTILS_H char *efreet_util_path_in_default(const char *section, const char *path); -char *efreet_util_path_to_file_id(const char *base, const char *path); +char *efreet_util_path_to_file_id(const char *path); Efreet_Desktop *efreet_util_desktop_by_file_id_get(const char *file_id); #endif