changeset 39:c07dbd386ded

fixed memory leak in tErrorLib
author Eric Wing <ewing@anscamobile.com>
date Mon, 23 May 2011 11:33:58 -0700
parents 71b465ff0622
children 2b0b55b7f8cf
files Isolated/tErrorLib.c
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Isolated/tErrorLib.c	Thu Apr 28 16:22:30 2011 -0700
+++ b/Isolated/tErrorLib.c	Mon May 23 11:33:58 2011 -0700
@@ -925,6 +925,17 @@
 		 * will always keep the strings at NULL, and don't mess 
 		 * with the asprintf/sprintf code.
 		 */
+		if(NULL != error_message->errorString)
+		{
+			/* Need to free errorString from previous pass otherwise we leak. 
+			 * Maybe there is a smarter way to avoid the free/malloc,
+			 * but this would probably require determining the length of the 
+			 * final string beforehand which probably implies two 
+			 * *printf calls which may or may not be better.
+			 */
+			free(error_message->errorString);
+			error_message->errorString = NULL;
+		}
 
 		ret_num_chars = vasprintf(&error_message->errorString, err_str, argp);
 		/* vasprintf returns -1 as an error */