[evolution-patches] calendar/gui/e-pub-utils.c: Memory cleanups
- From: Trent Lloyd <lathiat bur st>
- To: evolution-patches lists ximian com
- Subject: [evolution-patches] calendar/gui/e-pub-utils.c: Memory cleanups
- Date: Fri, 07 May 2004 20:57:11 +0800
Hi Guys,
This patch fixes a number of memory leaking issues with the e-pub-utils
stuff.
I've tested it and it appears to work still fine for me.
Cheers,
Trent
Index: calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2308
diff -u -r1.2308 ChangeLog
--- a/calendar/ChangeLog 7 May 2004 04:35:36 -0000 1.2308
+++ b/calendar/ChangeLog 7 May 2004 12:50:40 -0000
@@ -1,3 +1,17 @@
+2004-05-07 Trent Lloyd <lathiat bur st>
+
+ * gui/e-pub-utils.c: Make new e_pub_uri_new and e_pub_uri_free functions
+ to handle memory management better
+ (just_published): Handle NULL values of last_pub_time
+ (is_publish_time): Ditto
+ (e_pub_uri_from_xml): Free xmlChars not freed.
+ (e_pub_uri_to_xml): Free frequency not freed.
+ (e_pub_publish): Free data allocated in uri_list, use new
+ e_pub_uri_new/free functions.
+ * gui/e-pub-utils.h: Add prototypes for above new
+ e_pub_uri_new/e_pub_uri_free functions and reformat to look nicer and
+ conform with other headers.
+
2004-05-06 Larry Ewing <lewing ximian com>
* gui/dialogs/calendar-setup.c (source_to_dialog): use random
Index: calendar/gui/e-pub-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-pub-utils.c,v
retrieving revision 1.3
diff -u -r1.3 e-pub-utils.c
--- a/calendar/gui/e-pub-utils.c 10 Apr 2004 21:31:37 -0000 1.3
+++ b/calendar/gui/e-pub-utils.c 7 May 2004 12:50:42 -0000
@@ -34,6 +34,45 @@
#include "itip-utils.h"
#include "e-pub-utils.h"
+EPublishUri*
+e_pub_uri_new ()
+{
+ EPublishUri *tmp;
+
+ tmp = g_new0(EPublishUri, 1);
+
+ tmp->location = NULL;
+ tmp->username = NULL;
+ tmp->password = NULL;
+ tmp->last_pub_time = NULL;
+ tmp->calendars = NULL;
+
+ return tmp;
+}
+
+void
+e_pub_uri_free (EPublishUri *uri)
+{
+ GSList *l;
+
+ if (uri->location != NULL)
+ g_free(uri->location);
+ if (uri->username != NULL)
+ g_free(uri->username);
+ if (uri->password != NULL)
+ g_free(uri->password);
+ if (uri->last_pub_time != NULL)
+ g_free(uri->last_pub_time);
+
+ for (l = uri->calendars; l != NULL; l = l->next)
+ g_free(l->data);
+
+ g_slist_free(uri->calendars);
+
+ g_free(uri);
+ return;
+}
+
void
e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml)
{
@@ -54,6 +93,7 @@
if (strcmp (root->name, "uri") != 0) {
return;
}
+
location = xmlGetProp (root, "location");
enabled = xmlGetProp (root, "enabled");
frequency = xmlGetProp (root, "frequency");
@@ -82,6 +122,10 @@
xmlFree(location);
xmlFree(enabled);
+ xmlFree(frequency);
+ xmlFree(username);
+ xmlFree(publish_time);
+
xmlFreeDoc(doc);
return;
}
@@ -127,6 +171,7 @@
returned_buffer [xml_buffer_size] = '\0';
xmlFree (xml_buffer);
g_free (enabled);
+ g_free(frequency);
return returned_buffer;
}
@@ -136,7 +181,7 @@
icaltimezone *utc;
struct icaltimetype current_itt, adjust_itt;
- if (!uri->last_pub_time) {
+ if (!uri->last_pub_time || uri->last_pub_time == NULL) {
utc = icaltimezone_get_utc_timezone ();
current_itt = icaltime_current_time_with_zone (utc);
uri->last_pub_time = g_strdup (icaltime_as_ical_string (current_itt));
@@ -178,6 +223,8 @@
icaltimezone *utc;
struct icaltimetype current_itt, adjust_itt;
+ if (last_pub_time == NULL)
+ return FALSE;
if (strlen (last_pub_time) != 0) {
utc = icaltimezone_get_utc_timezone ();
adjust_itt = icaltime_from_string (last_pub_time);
@@ -223,7 +270,7 @@
gchar *xml = (gchar *)l->data;
- uri = g_new0 (EPublishUri, 1);
+ uri = e_pub_uri_new();
e_pub_uri_from_xml (uri, xml);
/* kludge to safeguard against loop from gconf update */
@@ -324,7 +371,7 @@
if (xml != NULL) {
uri_list = g_slist_append (uri_list, xml);
}
- g_free (uri);
+ e_pub_uri_free(uri);
}
if (published) {
@@ -332,6 +379,10 @@
calendar_config_set_free_busy (uri_list);
}
+ for (l = uri_list; l != NULL; l = l->next) {
+ g_free(l->data);
+ }
+
g_slist_free (uri_config_list);
g_slist_free (uri_list);
}
Index: calendar/gui/e-pub-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-pub-utils.h,v
retrieving revision 1.1
diff -u -r1.1 e-pub-utils.h
--- a/calendar/gui/e-pub-utils.h 13 Jan 2004 01:59:28 -0000 1.1
+++ b/calendar/gui/e-pub-utils.h 7 May 2004 12:50:42 -0000
@@ -53,9 +53,12 @@
typedef struct _EPublishUri EPublishUri;
-void e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml);
-gchar *e_pub_uri_to_xml (EPublishUri *uri);
-void e_pub_publish (gboolean publish) ;
+EPublishUri* e_pub_uri_init();
+void e_pub_uri_free (EPublishUri *uri);
+
+void e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml);
+gchar* e_pub_uri_to_xml (EPublishUri *uri);
+void e_pub_publish (gboolean publish) ;
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]