Commit 98eae3ab authored by Allen Winter's avatar Allen Winter
Browse files

Plug 2 groups of memory leaks in the parser plan2.

Thanks for the patch Eugene!
BUG: 315910
FIXED-IN: 4.11
parent 82791ebb
......@@ -64,6 +64,7 @@ HolidayParserDriverPlan::HolidayParserDriverPlan( const QString &planFilePath )
m_scanner->set_debug( m_traceScanning );
m_parser = new HolidayParserPlan( *this );
m_parser->set_debug_level( m_traceParsing );
m_fileToParse = new std::string( filePath().toLocal8Bit().data() );
parseMetadata();
}
......@@ -71,6 +72,7 @@ HolidayParserDriverPlan::~HolidayParserDriverPlan()
{
delete m_parser;
delete m_scanner;
delete m_fileToParse;
}
//TODO Figure why it doesn't compile
......@@ -165,6 +167,10 @@ QString HolidayParserDriverPlan::filePath()
return m_filePath;
}
std::string *HolidayParserDriverPlan::fileToParse() const
{
return m_fileToParse;
}
/*****************************************
Calendar and Date convenience routines
......
......@@ -23,6 +23,7 @@
#define KHOLIDAYS_HOLIDAYPARSERDRIVERPLAN_P_H
#include <fstream>
#include <string>
#include <QByteArray>
#include <QStringList>
......@@ -95,6 +96,7 @@ protected:
// Accessor methods for parser to talk to driver
QString filePath();
std::string *fileToParse() const;
// Calendar and date calculation utilities
int adjustedMonthNumber( int month );
......@@ -164,6 +166,8 @@ private:
int m_eventDay; // Event date fields
int m_eventColorName; // Color of event name text
int m_eventColorDay; // Color of event day number
std::string *m_fileToParse;
};
}
......
......@@ -210,7 +210,9 @@ namespace KHolidays
switch (yytype)
{
case 7: /* STRING */
{ free( ((*yyvaluep).sval) ); };
break;
default:
break;
}
......@@ -287,7 +289,7 @@ namespace KHolidays
#line 70 "holidayparserplan.ypp"
{
// initialize the initial location object
yylloc.begin.filename = new std::string( driver.filePath().toLocal8Bit().data() );
yylloc.begin.filename = driver.fileToParse();
yylloc.end.filename = yylloc.begin.filename;
}
/* Line 547 of yacc.c. */
......@@ -413,7 +415,12 @@ namespace KHolidays
case 5:
#line 130 "holidayparserplan.ypp"
{ driver.setFileCountryCode( QString::fromUtf8( (yysemantic_stack_[(2) - (2)].sval) ) ); ;}
{
char *s = yysemantic_stack_[(2) - (2)].sval;
driver.setFileCountryCode( QString::fromUtf8( s ) );
free( s );
yysemantic_stack_[(2) - (2)].sval = NULL;
}
break;
case 6:
......@@ -423,7 +430,12 @@ namespace KHolidays
case 7:
#line 134 "holidayparserplan.ypp"
{ driver.setFileLanguageCode( QString::fromUtf8( (yysemantic_stack_[(2) - (2)].sval) ) ); ;}
{
char *s = yysemantic_stack_[(2) - (2)].sval;
driver.setFileLanguageCode( QString::fromUtf8( s ) );
free( s );
yysemantic_stack_[(2) - (2)].sval = NULL;
}
break;
case 8:
......@@ -433,7 +445,12 @@ namespace KHolidays
case 9:
#line 138 "holidayparserplan.ypp"
{ driver.setFileName( QString::fromUtf8( (yysemantic_stack_[(2) - (2)].sval) ) ); ;}
{
char *s = yysemantic_stack_[(2) - (2)].sval;
driver.setFileName( QString::fromUtf8( s ) );
free( s );
yysemantic_stack_[(2) - (2)].sval = NULL;
}
break;
case 10:
......@@ -443,7 +460,12 @@ namespace KHolidays
case 11:
#line 142 "holidayparserplan.ypp"
{ driver.setFileDescription( QString::fromUtf8( (yysemantic_stack_[(2) - (2)].sval) ) ); ;}
{
char *s = yysemantic_stack_[(2) - (2)].sval;
driver.setFileDescription( QString::fromUtf8( s ) );
free( s );
yysemantic_stack_[(2) - (2)].sval = NULL;
}
break;
case 16:
......@@ -468,7 +490,12 @@ namespace KHolidays
case 20:
#line 161 "holidayparserplan.ypp"
{ driver.setEventName( QString::fromUtf8( (yysemantic_stack_[(1) - (1)].sval) ) ); ;}
{
char *s = yysemantic_stack_[(1) - (1)].sval;
driver.setEventName( QString::fromUtf8( s ) );
free( s );
yysemantic_stack_[(1) - (1)].sval = NULL;
}
break;
case 21:
......@@ -623,7 +650,12 @@ namespace KHolidays
case 51:
#line 208 "holidayparserplan.ypp"
{ (yyval.ival) = driver.julianDayFromEventName( (yysemantic_stack_[(1) - (1)].sval) ); ;}
{
char *s = yysemantic_stack_[(1) - (1)].sval;
(yyval.ival) = driver.julianDayFromEventName( s );
free( s );
yysemantic_stack_[(1) - (1)].sval = NULL;
}
break;
case 52:
......
......@@ -69,7 +69,7 @@
%initial-action
{
// initialize the initial location object
@$.begin.filename = new std::string( driver.filePath().toLocal8Bit().data() );
@$.begin.filename = driver.fileToParse();
@$.end.filename = @$.begin.filename;
};
......@@ -92,6 +92,8 @@
%token INOP PLUS MINUS SMALL YEAR LEAPYEAR SHIFT IF
%token LENGTH EASTER EQ NE LE GE LT GT PASCHA COUNTRY LANGUAGE NAME DESCRIPTION
%destructor { free( $$ ); } STRING
%left OR
%left AND
%right EQ NE LE GE LT GT
......@@ -127,19 +129,19 @@ metadata : countrycode languagecode name description
;
countrycode : { driver.setFileCountryCode( QString() ); }
| COUNTRY STRING { driver.setFileCountryCode( QString::fromUtf8( $2 ) ); }
| COUNTRY STRING { char *s = $2; driver.setFileCountryCode( QString::fromUtf8( s ) ); free( s ); $2 = NULL; }
;
languagecode : { driver.setFileLanguageCode( QString() ); }
| LANGUAGE STRING { driver.setFileLanguageCode( QString::fromUtf8( $2 ) ); }
| LANGUAGE STRING { char *s = $2; driver.setFileLanguageCode( QString::fromUtf8( s ) ); free( s ); $2 = NULL; }
;
name : { driver.setFileName( QString() ); }
| NAME STRING { driver.setFileName( QString::fromUtf8( $2 ) ); }
| NAME STRING { char *s = $2; driver.setFileName( QString::fromUtf8( s ) ); free( s ); $2 = NULL; }
;
description : { driver.setFileDescription( QString() ); }
| DESCRIPTION STRING { driver.setFileDescription( QString::fromUtf8( $2 ) ); }
| DESCRIPTION STRING { char *s = $2; driver.setFileDescription( QString::fromUtf8( s ) ); free( s ); $2 = NULL; }
;
list :
......@@ -158,7 +160,7 @@ daycolor : { driver.setEventColorDay( 0 ); }
| COLOR { driver.setEventColorDay( $1 ); }
;
eventname : STRING { driver.setEventName( QString::fromUtf8( $1 ) ); }
eventname : STRING { driver.setEventName( char *s = $1; QString::fromUtf8( s ) ); free( s ); $1 = NULL; }
;
calendar : { driver.setEventCalendarType( "gregorian" ); }
......@@ -205,7 +207,7 @@ date : pexpr '.' month { driver.setEventDate( -99999, $3, $1 ); }
| pexpr { driver.setEventDate( $1 ); }
;
reldate : STRING { $$ = driver.julianDayFromEventName( $1 ); }
reldate : STRING { char *s = $1; $$ = driver.julianDayFromEventName( s ); free( s ); $1 = NULL}
| EASTER { $$ = driver.julianDayFromEaster(); }
| PASCHA { $$ = driver.julianDayFromPascha(); }
| pexpr '.' month { $$ = driver.julianDayFromMonthDay( $3, $1 ); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment