Memory management

SVN revision: 29114
This commit is contained in:
Sebastian Dransfeld 2007-03-25 13:10:09 +00:00
parent 2f086b0e73
commit fe0fbd4189
3 changed files with 21 additions and 18 deletions

View File

@ -6,23 +6,20 @@ int
ef_cb_utils(void) ef_cb_utils(void)
{ {
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
char *tmp; char *tmp1;
const char *tmp2;
printf("\n"); printf("\n");
tmp = efreet_util_path_in_default("applications", tmp1 = efreet_util_path_in_default("applications",
"/usr/share/applications/test.desktop"); "/usr/share/applications/test.desktop");
if (tmp) if (tmp1)
{ {
printf("%s\n", tmp); printf("%s\n", tmp1);
free(tmp); free(tmp1);
} }
tmp = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop"); tmp2 = efreet_util_path_to_file_id("/usr/share/applications/this/tmp/test.desktop");
if (tmp) if (tmp2) printf("%s\n", tmp2);
{
printf("%s\n", tmp);
free(tmp);
}
desktop = efreet_util_desktop_file_id_find("kde-kresources.desktop"); desktop = efreet_util_desktop_file_id_find("kde-kresources.desktop");
printf("kde-kresources.desktop: %p\n", desktop); printf("kde-kresources.desktop: %p\n", desktop);

View File

@ -36,7 +36,10 @@ efreet_util_init(void)
desktop_by_file_id = ecore_hash_new(ecore_str_hash, ecore_str_compare); desktop_by_file_id = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(desktop_by_file_id, ECORE_FREE_CB(ecore_string_release)); ecore_hash_set_free_key(desktop_by_file_id, ECORE_FREE_CB(ecore_string_release));
desktop_by_exec = ecore_hash_new(ecore_str_hash, ecore_str_compare); desktop_by_exec = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(desktop_by_exec, ECORE_FREE_CB(ecore_string_release));
file_id_by_desktop_path = ecore_hash_new(ecore_str_hash, ecore_str_compare); file_id_by_desktop_path = ecore_hash_new(ecore_str_hash, ecore_str_compare);
ecore_hash_set_free_key(file_id_by_desktop_path, ECORE_FREE_CB(ecore_string_release));
ecore_hash_set_free_value(file_id_by_desktop_path, ECORE_FREE_CB(ecore_string_release));
fill = NEW(Efreet_Cache_Fill, 1); fill = NEW(Efreet_Cache_Fill, 1);
fill->dirs = ecore_list_new(); fill->dirs = ecore_list_new();
@ -105,12 +108,13 @@ efreet_util_path_in_default(const char *section, const char *path)
return ret; return ret;
} }
char * const char *
efreet_util_path_to_file_id(const char *path) efreet_util_path_to_file_id(const char *path)
{ {
size_t len; size_t len;
char *file_id, *p; char *tmp, *p;
char *base; char *base;
const char *file_id = NULL;
if (!path) return NULL; if (!path) return NULL;
file_id = ecore_hash_get(file_id_by_desktop_path, path); file_id = ecore_hash_get(file_id_by_desktop_path, path);
@ -131,16 +135,18 @@ efreet_util_path_to_file_id(const char *path)
return NULL; return NULL;
} }
file_id = strdup(path + len + 1); tmp = strdup(path + len + 1);
p = file_id; p = tmp;
while (*p) while (*p)
{ {
if (*p == '/') *p = '-'; if (*p == '/') *p = '-';
p++; p++;
} }
free(base); free(base);
if (file_id) ecore_hash_set(file_id_by_desktop_path, (void *)ecore_string_instance(path), file_id = ecore_string_instance(tmp);
(void *)ecore_string_instance(file_id)); free(tmp);
ecore_hash_set(file_id_by_desktop_path, (void *)ecore_string_instance(path),
(void *)file_id);
return file_id; return file_id;
} }

View File

@ -3,7 +3,7 @@
#define EFREET_UTILS_H #define EFREET_UTILS_H
char *efreet_util_path_in_default(const char *section, const char *path); char *efreet_util_path_in_default(const char *section, const char *path);
char *efreet_util_path_to_file_id(const char *path); const char *efreet_util_path_to_file_id(const char *path);
Efreet_Desktop *efreet_util_desktop_file_id_find(const char *file_id); Efreet_Desktop *efreet_util_desktop_file_id_find(const char *file_id);
Efreet_Desktop *efreet_util_desktop_exec_find(const char *exec); Efreet_Desktop *efreet_util_desktop_exec_find(const char *exec);