[PATCH 3/5] wpp: Free some filename strings after processing an include (Valgrind). (try 3)

Matteo Bruni mbruni at codeweavers.com
Tue Jun 24 15:25:28 CDT 2014


The if condition might look somewhat weird but the include case is the
only one where a new filename was stored in pp_status.input by the
matching push_buffer().
---
 libs/wpp/ppl.l | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libs/wpp/ppl.l b/libs/wpp/ppl.l
index 9655e34..cebb6db 100644
--- a/libs/wpp/ppl.l
+++ b/libs/wpp/ppl.l
@@ -1340,6 +1340,8 @@ static bufferstackentry_t *pop_buffer(void)
 		bufferstack[bufferstackidx].define->expanding = 0;
 	else
 	{
+		includelogicentry_t *iep = NULL;
+
 		if(!bufferstack[bufferstackidx].should_pop)
 		{
 			wpp_callbacks->close(pp_status.file);
@@ -1351,7 +1353,7 @@ static bufferstackentry_t *pop_buffer(void)
 				pp_entry_t *ppp = pplookup(pp_incl_state.ppp);
 				if(ppp)
 				{
-					includelogicentry_t *iep = pp_xmalloc(sizeof(includelogicentry_t));
+					iep = pp_xmalloc(sizeof(includelogicentry_t));
 					if(!iep)
 						return NULL;
 
@@ -1366,17 +1368,21 @@ static bufferstackentry_t *pop_buffer(void)
 					if(pp_status.debug)
 						fprintf(stderr, "pop_buffer: %s:%d: includelogic added, include_ppp='%s', file='%s'\n", bufferstack[bufferstackidx].filename, bufferstack[bufferstackidx].line_number, pp_incl_state.ppp, iep->filename);
 				}
-				else
-					free(bufferstack[bufferstackidx].include_filename);
 			}
 			free(pp_incl_state.ppp);
 			pp_incl_state	= bufferstack[bufferstackidx].incl;
 
 		}
+		if (bufferstack[bufferstackidx].include_filename)
+		{
+			free((void *)pp_status.input);
+			pp_status.input = bufferstack[bufferstackidx].filename;
+		}
 		pp_status.line_number = bufferstack[bufferstackidx].line_number;
 		pp_status.char_number = bufferstack[bufferstackidx].char_number;
-		pp_status.input  = bufferstack[bufferstackidx].filename;
 		ncontinuations = bufferstack[bufferstackidx].ncontinuations;
+		if (!iep)
+			free(bufferstack[bufferstackidx].include_filename);
 	}
 
 	if(ppy_debug)
-- 
1.8.5.5




More information about the wine-patches mailing list