Re: [evolution-patches] [Evolution-hackers] Fix for "agressive" memory segmentation



On Thu, 2006-07-06 at 15:36 -0400, Jeffrey Stedfast wrote:
> On Thu, 2006-07-06 at 21:32 +0200, Philip Van Hoof wrote:
> > On Thu, 2006-07-06 at 15:18 -0400, Jeffrey Stedfast wrote:
> > > For some strange reason I thought the pstring stuff already did that,
> > > oops. I guess I was thinking of similar code I wrote a few years back
> > > for another project...
> > > 
> > > This patch does it the way I had done it in another project of mine
> > 
> > Yours looks a little bit more clean in naming and stuff like that. It
> > probably does more or less the same? So I'd say commit one of the two?
> 
> yea, it's basically the same as what you did

Err. I don't want to disappoint you. But measuring your implementation
shows that you are allocated three megabytes more data than the original
one.

Mine didn't do that because I freed the str in the first if-block.

The attached patch fixes it. The attached valgrind reports show it.

Ok to commit this? Will you commit it?

 
-- 
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-string-utils.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-string-utils.c,v
retrieving revision 1.6
diff -u -r1.6 camel-string-utils.c
--- camel-string-utils.c	6 Jul 2006 19:43:47 -0000	1.6
+++ camel-string-utils.c	6 Jul 2006 21:34:32 -0000
@@ -164,10 +164,10 @@
 	char *pstr;
 	int count;
 	
-	if (s == NULL)
+	if (str == NULL)
 		return NULL;
 	
-	if (s[0] == '\0') {
+	if (str[0] == '\0') {
 		if (own)
 			g_free (str);
 		return "";
@@ -180,6 +180,7 @@
 	if (g_hash_table_lookup_extended (pstring_table, str, (void **) &pstr, &pcount)) {
 		count = GPOINTER_TO_INT (pcount) + 1;
 		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (count));
+		g_free (str);
 	} else {
 		pstr = own ? str : g_strdup (str);
 		g_hash_table_insert (pstring_table, pstr, GINT_TO_POINTER (1));

Attachment: valgrind.tar.gz
Description: application/compressed-tar



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