cpw.nader.asynclogging-3: f03e3495: Fixed up a few memory leaks in commonlog...
morshed.nader at gmail.com
morshed.nader at gmail.com
Thu Jan 5 19:16:56 EST 2012
----------------------------------------------------------------------
Revision: f03e349511d408f28f64610504936abe0b272c80
Parent: 738865ce749562495b65abdcc8acdf28c707f0f5
Author: morshed.nader at gmail.com
Date: 01/05/12 19:10:08
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/f03e349511d408f28f64610504936abe0b272c80
Changelog:
Fixed up a few memory leaks in commonlog.c
Updated the synchronous total_size call to use GFileEnumerator
Changes against parent 738865ce749562495b65abdcc8acdf28c707f0f5
patched libpurple/commonlog.c
-------------- next part --------------
============================================================
--- libpurple/commonlog.c a43ac6e3d93cf668e6e8aa381e87e096cb080a5c
+++ libpurple/commonlog.c b760c69be1d2591fff088ae10133dfc5159b656e
@@ -919,19 +919,22 @@ purple_common_log_list(PurpleLogChatType
G_FILE_QUERY_INFO_NONE, cancellable, &err);
if (enumerator == NULL) {
+ /* If the directory doesn't exist, we just don't have logs for them */
+ g_object_unref(dir);
+
if (err->code == G_FILE_ERROR_NOENT)
g_clear_error(&err);
else
g_propagate_error(error, err);
- g_object_unref(dir);
-
return NULL;
}
g_clear_error(&err);
- while ((info = g_file_enumerator_next_file(enumerator, cancellable, &err)) != NULL) {
+ while ((info = g_file_enumerator_next_file(enumerator,
+ cancellable, &err)) != NULL)
+ {
GFile *child_file;
PurpleLog *log;
gchar *child_path;
@@ -958,7 +961,7 @@ purple_common_log_list(PurpleLogChatType
g_propagate_error(error, err);
return NULL;
}
-
+
return list;
}
@@ -1129,11 +1132,12 @@ purple_common_log_total_size(PurpleLogCh
GError **error)
{
// _purple_logsize_user *lu;
- GDir *dir;
GError *err = NULL;
- const gchar *filename;
+ GFile *dir;
+ GFileEnumerator *enumerator;
+ GFileInfo *info;
gchar *path;
- gssize size = 0;//, total;
+ gssize total = 0;
// gpointer ptrsize;
g_return_val_if_fail(name != NULL, -1);
@@ -1151,66 +1155,60 @@ purple_common_log_total_size(PurpleLogCh
return -1;
}
- dir = g_dir_open(path, 0, &err);
+ dir = g_file_new_for_path(path);
+ g_free(path);
- if (dir == NULL){
- g_free(path);
+ enumerator = g_file_enumerate_children(dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NONE, cancellable, &err);
+ if (enumerator == NULL){
/* If the directory doesn't exist, we just don't have logs for them */
- if (err->code == G_FILE_ERROR_NOENT)
+ g_object_unref(dir);
+
+ if (err->code == G_FILE_ERROR_NOENT) {
+ g_clear_error(&err);
return 0;
- else {
+ } else {
g_propagate_error(error, err);
return -1;
}
}
- while ((filename = g_dir_read_name(dir)) != NULL) {
- if (g_cancellable_set_error_if_cancelled(cancellable, error)) {
- g_dir_close(dir);
- g_free(path);
+ g_clear_error(&err);
- return -1;
- }
+ while ((info = g_file_enumerator_next_file(enumerator,
+ cancellable, &err)) != NULL)
+ {
+ GFile *child_file;
+ gchar *child_path;
+ goffset size;
- if (purple_str_has_suffix(filename, ext) &&
- strlen(filename) >= 17 + strlen(ext))
- {
- GFile *file;
- GFileInfo *info;
- gchar *tmp = g_build_filename(path, filename, NULL);
- goffset file_size;
+ child_file = g_file_get_child(dir, g_file_info_get_name(info));
+ child_path = g_file_get_path(child_file);
+ g_object_unref(child_file);
- file = g_file_new_for_path(tmp);
- info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
- G_FILE_QUERY_INFO_NONE, cancellable, error);
+ if (!purple_str_has_suffix(child_path, ext)) {
+ g_free(child_path);
+ continue;
+ }
- if (info == NULL) {
- g_dir_close(dir);
- g_object_unref(file);
- g_free(path);
- g_free(tmp);
+ g_free(child_path);
- return -1;
- }
+ size = g_file_info_get_size(info);
+ g_assert(size >= 0);
+ total += size;
+ }
- file_size = g_file_info_get_size(info);
- g_assert(size >= 0);
+ g_object_unref(dir);
+ g_object_unref(enumerator);
- size += file_size;
-
- purple_debug_info("commonlog", "file size for %s: %" G_GUINT64_FORMAT "\n", tmp, file_size);
-
- g_object_unref(info);
- g_object_unref(file);
- g_free(tmp);
- }
+ if (err != NULL) {
+ g_propagate_error(error, err);
+ return -1;
}
- g_dir_close(dir);
- g_free(path);
-
- return size;
+ return total;
}
void
@@ -1303,15 +1301,15 @@ purple_common_log_total_size_async_3(GOb
child_path = g_file_get_path(child_file);
g_object_unref(child_file);
- size = g_file_info_get_size(info);
- g_assert(size >= 0);
-
if (!purple_str_has_suffix(child_path, data->ext)) {
g_free(child_path);
continue;
}
g_free(child_path);
+
+ size = g_file_info_get_size(info);
+ g_assert(size >= 0);
data->total += size;
}
More information about the Commits
mailing list