[evolution-patches] Avoiding a strdup in camel-folder-summar.c



This patch is unrelated to the mmap() patches that I've also been
sending.

It basically avoids an strdup() by implementing a smarter free_token().

ps. I'm keeping Varadhan and Jeffrey in CC because the mailinglist
aren't working (or very slow).

-- 
Philip Van Hoof, software developer at x-tend 
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
work: vanhoof at x-tend dot be 
http://www.pvanhoof.be - http://www.x-tend.be
? camel-mime-tables.c
Index: camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.149
diff -u -r1.149 camel-folder-summary.c
--- camel-folder-summary.c	6 Jul 2006 19:43:46 -0000	1.149
+++ camel-folder-summary.c	9 Jul 2006 16:43:30 -0000
@@ -1339,7 +1339,7 @@
 		if (len <= 0) {
 			ret = NULL;
 		} else if (len<= tokens_len) {
-			ret = g_strdup(tokens[len-1]);
+			ret = tokens[len-1];
 		} else {
 			io(printf ("Invalid token encountered: %d", len));
 			*str = NULL;
@@ -1853,6 +1853,22 @@
 	return ci;
 }
 
+static void
+free_token (gchar *token)
+{
+	gint i=0;
+	gboolean no=FALSE;
+
+	for (i=0; (i < tokens_len); i++)
+	{
+		if (tokens[i] == token)
+			no = TRUE;
+	}
+
+	if (!no)
+		g_free (token);
+}
+
 static CamelMessageContentInfo *
 content_info_load(CamelFolderSummary *s, FILE *in)
 {
@@ -1860,7 +1876,7 @@
 	char *type, *subtype;
 	guint32 count, i;
 	CamelContentType *ct;
-
+	
 	io(printf("Loading content info\n"));
 
 	ci = camel_folder_summary_content_info_new(s);
@@ -1868,8 +1884,11 @@
 	camel_folder_summary_decode_token(in, &type);
 	camel_folder_summary_decode_token(in, &subtype);
 	ct = camel_content_type_new(type, subtype);
-	g_free(type);		/* can this be removed? */
-	g_free(subtype);
+
+
+	free_token (type);		/* can this be removed? */
+	free_token (subtype);
+
 	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
 		goto error;
 	
@@ -1882,8 +1901,8 @@
 		
 		camel_content_type_set_param(ct, name, value);
 		/* TODO: do this so we dont have to double alloc/free */
-		g_free(name);
-		g_free(value);
+		free_token (name);
+		free_token (value);
 	}
 	ci->type = ct;
 
@@ -1937,9 +1956,9 @@
 content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci)
 {
 	camel_content_type_unref(ci->type);
-	g_free(ci->id);
-	g_free(ci->description);
-	g_free(ci->encoding);
+	free_token (ci->id);
+	free_token (ci->description);
+	free_token (ci->encoding);
 	e_memchunk_free(s->content_info_chunks, ci);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]