Skip to contentSkip to conversation

PATCH: Memory leak appending original mail

PATCH Ben Schmidt 2 participants 5 messages Jan 26, 2010 – Feb 16, 2010

lore
Share & tools
lore
#0 lore raw

I found a memory leak. Patch attached.
Ben.

src/prepstdreply.c +1 -0
diff -r 99ec9f826d35 src/prepstdreply.c
@@ -145,6 +145,7 @@
 				value = concatstr(3, value, " ", str);
 				if(tmp)
 					myfree(tmp);
+				myfree(str);
 				count++;
 			}
 			if(str)
#1 lore raw

How tremendously embarrassing...

Note to self: The correct way to fix a memory leak is not to introduce a double free.

Revised patch attached.

Ben.

Quoted 3 lines · Ben Schmidt

I found a memory leak. Patch attached.
Ben.

src/prepstdreply.c +2 -0
diff -r f48f18a405ee src/prepstdreply.c
@@ -145,6 +145,8 @@
 				value = concatstr(3, value, " ", str);
 				if(tmp)
 					myfree(tmp);
+				myfree(str);
+				str = NULL;
 				count++;
 			}
 			if(str)
#2 lore raw
In reply to Ben Schmidt
Quoted 4 lines · Ben Schmidt

How tremendously embarrassing...

Note to self: The correct way to fix a memory leak is not to introduce a double free.

True :-)

Quoted 1 line

Revised patch attached.

I looked at the code, and got thinking. Since the loop is only entered if str is not NULL, and str is only used inside the loop, couldn't we just free str inside the loop?

Proposed patch attached.

Morten

Signature · 3 lines
Morten Shearman Kirkegaard <[email protected]>
CTO, FableTech
http://fabletech.com/

Index: src/prepstdreply.c
===================================================================
RCS file: /home/mmj/MMJCVS/mlmmj/src/prepstdreply.c,v retrieving revision 1.28

prepstdreply.c +1 -2
diff -u -r1.28 prepstdreply.c
@@ -145,10 +145,9 @@
 				value = concatstr(3, value, " ", str);
 				if(tmp)
 					myfree(tmp);
+				myfree(str);
 				count++;
 			}
-			if(str)
-				myfree(str);
 			close(mailfd);
 		}else{
 			log_error(LOG_ARGS, "Could not substitute $originalmail$ (mailname == %s)",mailname);
#3 lore raw
In reply to Ben Schmidt
Quoted 5 lines

I looked at the code, and got thinking. Since the loop is only entered if str is not NULL, and str is only used inside the loop, couldn't we just free str inside the loop?

Proposed patch attached.

Yeah, that works! Go for it!

Ben.

#4 lore raw
In reply to Ben Schmidt
Quoted 7 lines · Ben Schmidt
Quoted 5 lines

I looked at the code, and got thinking. Since the loop is only entered if str is not NULL, and str is only used inside the loop, couldn't we just free str inside the loop?

Proposed patch attached.

Yeah, that works! Go for it!

Committed to CVS.

Morten

Signature · 3 lines
Morten Shearman Kirkegaard <[email protected]>
CTO, FableTech
http://fabletech.com/