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,27 +736,32 @@ 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);
while (!finished) if (path)
{ {
start = end; end = path;
do /* FIXME: There is probably a better way to do this. */ while (!finished)
{ {
while ((*end != ';') && (*end != ':') && (*end != ',') start = end;
&& (*end != '\0')) do /* FIXME: There is probably a better way to do this. */
end++; {
} while ((*end != ';') && (*end != ':') && (*end != ',')
while ((end != paths) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ && (*end != '\0'))
/* FIXME: We still need to unescape it now. */ end++;
temp = *end; }
if (*end == '\0') while ((end != path) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */
finished = 1; /* FIXME: We still need to unescape it now. */
else temp = *end;
*end = '\0'; if (*end == '\0')
ecore_hash_set(result, strdup(start), strdup(start)); finished = 1;
if ((*end) != temp) else
*end = temp; *end = '\0';
end++; ecore_hash_set(result, strdup(start), strdup(start));
if ((*end) != temp)
*end = temp;
end++;
}
free(path);
} }
} }
} }
@ -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,29 +795,32 @@ ecore_desktop_paths_to_list(char *paths)
int finished = 0; int finished = 0;
path = strdup(paths); path = strdup(paths);
end = path; if (path)
while (!finished) {
{ end = path;
start = end; while (!finished)
do /* FIXME: There is probably a better way to do this. */ {
{ start = end;
while ((*end != ';') && (*end != ':') && (*end != ',') do /* FIXME: There is probably a better way to do this. */
&& (*end != '\0')) {
end++; while ((*end != ';') && (*end != ':') && (*end != ',')
} && (*end != '\0'))
while ((end != path) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */ end++;
/* FIXME: We still need to unescape it now. */ }
temp = *end; while ((end != path) && (*(end - 1) == '\\') && (*end != '\0')); /* Ignore any escaped ;:, */
if (*end == '\0') /* FIXME: We still need to unescape it now. */
finished = 1; temp = *end;
else if (*end == '\0')
*end = '\0'; finished = 1;
ecore_list_append(result, strdup(start)); else
if ((*end) != temp) *end = '\0';
*end = temp; ecore_list_append(result, strdup(start));
end++; if ((*end) != temp)
} *end = temp;
free(path); end++;
}
free(path);
}
} }
} }
return result; return result;