Fix some of the memory leaks. There are more leaks, but it's just me

being conservative and strduping when it's- probably not needed.  I'll
double check them all and sort them out later today.


SVN revision: 24849
This commit is contained in:
David Walter Seikel 2006-08-17 20:24:36 +00:00
parent 35d34dee92
commit f92d643c5f
3 changed files with 66 additions and 53 deletions

View File

@ -107,8 +107,8 @@ extern "C"
const void *data); const void *data);
EAPI int ecore_desktop_paths_shutdown(void); EAPI int ecore_desktop_paths_shutdown(void);
Ecore_Hash *ecore_desktop_paths_to_hash(char *paths); Ecore_Hash *ecore_desktop_paths_to_hash(const char *paths);
Ecore_List *ecore_desktop_paths_to_list(char *paths); Ecore_List *ecore_desktop_paths_to_list(const char *paths);
EAPI int ecore_desktop_init(void); EAPI int ecore_desktop_init(void);
EAPI int ecore_desktop_shutdown(void); EAPI int ecore_desktop_shutdown(void);

View File

@ -26,6 +26,8 @@ static const char *ext[] = { ".png", ".svgz", ".svg", ".xpm", "", NULL };
* Using the search algorithm specified by freedesktop.org, * Using the search algorithm specified by freedesktop.org,
* search for an icon in the currently installed set of icon themes. * search for an icon in the currently installed set of icon themes.
* *
* The returned string needs to be freed eventually.
*
* @param icon The name of the required icon. * @param icon The name of the required icon.
* @param icon_size The size of the required icon. * @param icon_size The size of the required icon.
* @param icon_theme The theme of the required icon. * @param icon_theme The theme of the required icon.

View File

@ -273,6 +273,7 @@ ecore_desktop_paths_file_find(Ecore_List * paths, char *file, int sub,
sprintf(temp, "%s%s", this_path, file); sprintf(temp, "%s%s", this_path, file);
if (stat(temp, &path_stat) == 0) if (stat(temp, &path_stat) == 0)
{ {
/* FIXME: This is defensive but leaks. */
path = strdup(temp); path = strdup(temp);
if (func) if (func)
if (func(data, path)) if (func(data, path))
@ -314,12 +315,12 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
/* Merge the results, there are probably some duplicates. */ /* Merge the results, there are probably some duplicates. */
if (type) if (type)
types = ecore_desktop_paths_to_list(strdup(type)); types = ecore_desktop_paths_to_list(type);
if (gnome_extra) if (gnome_extra)
gnome_extras = ecore_desktop_paths_to_list(strdup(gnome_extra)); gnome_extras = ecore_desktop_paths_to_list(gnome_extra);
#ifdef KDE_SUPPORT #ifdef KDE_SUPPORT
if (kde) if (kde)
kdes = ecore_desktop_paths_to_list(strdup(kde)); kdes = ecore_desktop_paths_to_list(kde);
#endif #endif
paths = ecore_list_new(); paths = ecore_list_new();
@ -333,7 +334,7 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
{ {
Ecore_List *befores; Ecore_List *befores;
befores = ecore_desktop_paths_to_list(strdup(before)); befores = ecore_desktop_paths_to_list(before);
if (befores) if (befores)
{ {
char *this_before; char *this_before;
@ -356,7 +357,7 @@ _ecore_desktop_paths_get(char *before, char *env_home, char *env,
value = getenv(env_home); value = getenv(env_home);
if ((value == NULL) || (value[0] == '\0')) if ((value == NULL) || (value[0] == '\0'))
value = env_home_default; value = env_home_default;
env_list = ecore_desktop_paths_to_list(strdup(value)); env_list = ecore_desktop_paths_to_list(value);
if (env_list && types) if (env_list && types)
{ {
char *this_env, *this_type; char *this_env, *this_type;
@ -580,6 +581,7 @@ ecore_desktop_paths_recursive_search(char *path, char *file,
{ {
if (strcmp(basename(info_text), file) == 0) if (strcmp(basename(info_text), file) == 0)
{ {
/* FIXME: This is defensive but leaks. */
fpath = strdup(info_text); fpath = strdup(info_text);
if (func) if (func)
if (func(data, path)) if (func(data, path))
@ -718,9 +720,10 @@ _ecore_desktop_paths_cb_exe_exit(void *data, int type, void *event)
* @param paths A list of paths. * @param paths A list of paths.
*/ */
Ecore_Hash * Ecore_Hash *
ecore_desktop_paths_to_hash(char *paths) ecore_desktop_paths_to_hash(const char *paths)
{ {
Ecore_Hash *result; Ecore_Hash *result;
char *path;
result = ecore_hash_new(ecore_str_hash, ecore_str_compare); result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
if (result) if (result)
@ -733,7 +736,10 @@ ecore_desktop_paths_to_hash(char *paths)
char *start, *end, temp; char *start, *end, temp;
int finished = 0; int finished = 0;
end = paths; path = strdup(paths);
if (path)
{
end = path;
while (!finished) while (!finished)
{ {
start = end; start = end;
@ -743,7 +749,7 @@ ecore_desktop_paths_to_hash(char *paths)
&& (*end != '\0')) && (*end != '\0'))
end++; end++;
} }
while ((end != paths) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ while ((end != path) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */
/* FIXME: We still need to unescape it now. */ /* FIXME: We still need to unescape it now. */
temp = *end; temp = *end;
if (*end == '\0') if (*end == '\0')
@ -755,6 +761,8 @@ ecore_desktop_paths_to_hash(char *paths)
*end = temp; *end = temp;
end++; end++;
} }
free(path);
}
} }
} }
return result; return result;
@ -771,7 +779,7 @@ ecore_desktop_paths_to_hash(char *paths)
* @param paths A list of paths. * @param paths A list of paths.
*/ */
Ecore_List * Ecore_List *
ecore_desktop_paths_to_list(char *paths) ecore_desktop_paths_to_list(const char *paths)
{ {
Ecore_List *result; Ecore_List *result;
char *path; char *path;
@ -787,6 +795,8 @@ ecore_desktop_paths_to_list(char *paths)
int finished = 0; int finished = 0;
path = strdup(paths); path = strdup(paths);
if (path)
{
end = path; end = path;
while (!finished) while (!finished)
{ {
@ -812,5 +822,6 @@ ecore_desktop_paths_to_list(char *paths)
free(path); free(path);
} }
} }
}
return result; return result;
} }