--- a/src/log.c Tue Apr 11 16:02:57 2006 +0000
+++ b/src/log.c Tue Apr 11 16:06:24 2006 +0000
@@ -76,16 +76,26 @@
GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account,
GaimConversation *conv, time_t time, const struct tm *tm)
- GaimLog *log = g_new0(GaimLog, 1);
+ /* IMPORTANT: Make sure to initialize all the members of GaimLog */ + log = g_slice_new(GaimLog); log->name = g_strdup(gaim_normalize(account, name));
+ log->logger = gaim_log_logger_get();
- log->tm = g_new0(struct tm, 1);
+ /* There's no need to zero this as we immediately do a direct copy. */ + log->tm = g_slice_new(struct tm); #ifdef HAVE_STRUCT_TM_TM_ZONE
@@ -101,7 +111,7 @@
- log->logger = gaim_log_logger_get();
if (log->logger && log->logger->create)
log->logger->create(log);
@@ -120,10 +130,10 @@
/* XXX: This is so wrong... */
g_free((char *)log->tm->tm_zone);
+ g_slice_free(struct tm, log->tm);
+ g_slice_free(GaimLog, log); void gaim_log_write(GaimLog *log, GaimMessageFlags type,
@@ -504,7 +514,8 @@
if (set->normalized_name != set->name)
g_free(set->normalized_name);
+ g_slice_free(GaimLogSet, set); GList *gaim_log_get_system_logs(GaimAccount *account)
@@ -652,7 +663,7 @@
- log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
+ log->logger_data = data = g_slice_new0(GaimLogCommonLoggerData); data->file = g_fopen(path, "a");
@@ -728,7 +739,8 @@
- log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
+ log->logger_data = data = g_slice_new0(GaimLogCommonLoggerData); data->path = g_build_filename(path, filename, NULL);
list = g_list_prepend(list, log);
@@ -860,7 +872,10 @@
/* Don't worry about the cast, name will point to dynamically allocated memory shortly. */
while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) {
- GaimLogSet *set = g_new0(GaimLogSet, 1);
+ /* IMPORTANT: Always initialize all members of GaimLogSet */ + set = g_slice_new(GaimLogSet); /* Unescape the filename. */
name = g_strdup(gaim_unescape_filename(name));
@@ -868,12 +883,13 @@
/* Get the (possibly new) length of name. */
+ set->type = GAIM_LOG_IM;
+ /* set->buddy is always set below */ set->normalized_name = g_strdup(gaim_normalize(account, name));
/* Chat for .chat or .system at the end of the name to determine the type. */
- set->type = GAIM_LOG_IM;
gchar *tmp = &name[len - 7];
if (!strcmp(tmp, ".system")) {
@@ -892,6 +908,8 @@
/* Determine if this (account, name) combination exists as a buddy. */
set->buddy = (gaim_find_buddy(account, name) != NULL);
log_add_log_set_to_hash(sets, set);
@@ -1117,7 +1135,8 @@
+ g_slice_free(GaimLogCommonLoggerData, data); @@ -1248,7 +1267,8 @@
+ g_slice_free(GaimLogCommonLoggerData, data); @@ -1371,10 +1391,14 @@
log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
log->logger = old_logger;
log->time = (time_t)idx_time;
- data = g_new0(struct old_logger_data, 1);
+ /* IMPORTANT: Always set all members of struct old_logger_data */ + data = g_slice_new(struct old_logger_data); + data->pathref = gaim_stringref_ref(pathref); - data->pathref = gaim_stringref_ref(pathref);
list = g_list_prepend(list, log);
@@ -1450,10 +1474,14 @@
log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
log->logger = old_logger;
- data = g_new0(struct old_logger_data, 1);
+ /* IMPORTANT: Always set all members of struct old_logger_data */ + data = g_slice_new(struct old_logger_data); + data->pathref = gaim_stringref_ref(pathref); - data->pathref = gaim_stringref_ref(pathref);
list = g_list_prepend(list, log);
@@ -1505,10 +1533,14 @@
log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
log->logger = old_logger;
- data = g_new0(struct old_logger_data, 1);
+ /* IMPORTANT: Always set all members of struct old_logger_data */ + data = g_slice_new(struct old_logger_data); + data->pathref = gaim_stringref_ref(pathref); - data->pathref = gaim_stringref_ref(pathref);
list = g_list_prepend(list, log);
@@ -1626,7 +1658,8 @@
- set = g_new0(GaimLogSet, 1);
+ /* IMPORTANT: Always set all members of GaimLogSet */ + set = g_slice_new(GaimLogSet); /* Chat for .chat at the end of the name to determine the type. */
@@ -1665,6 +1698,12 @@
@@ -1674,5 +1713,5 @@
struct old_logger_data *data = log->logger_data;
gaim_stringref_unref(data->pathref);
+ g_slice_free(struct old_logger_data, data); --- a/src/log.h Tue Apr 11 16:02:57 2006 +0000
+++ b/src/log.h Tue Apr 11 16:06:24 2006 +0000
@@ -126,6 +126,9 @@
timezone fields, else @c NULL.
Do NOT modify anything in this struct.*/
+ /* IMPORTANT: Some code in log.c allocates these without zeroing them. + * IMPORTANT: Update that code if you add members here. */ @@ -160,6 +163,9 @@
@a name. It must be set, and
may be set to the same pointer
+ /* IMPORTANT: Some code in log.c allocates these without zeroing them. + * IMPORTANT: Update that code if you add members here. */