Plug leaks in geometry parsing

When parsing a geometry file, don't leak the elements we've created.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2012-03-15 09:34:20 +00:00
parent 937d40492c
commit 9452165837
3 changed files with 25 additions and 15 deletions

View File

@ -613,9 +613,6 @@ StmtSetMerge(ParseCommon * stmt, unsigned merge)
return merge; return merge;
} }
static void
FreeStmt(ParseCommon *stmt);
static void static void
FreeExpr(ExprDef *expr) FreeExpr(ExprDef *expr)
{ {
@ -677,7 +674,7 @@ FreeInclude(IncludeStmt *incl)
} }
} }
static void void
FreeStmt(ParseCommon *stmt) FreeStmt(ParseCommon *stmt)
{ {
ParseCommon *next; ParseCommon *next;

View File

@ -154,4 +154,7 @@ extern void setScanState(const char * /* file */ ,
int /* line */ int /* line */
); );
extern void FreeStmt(ParseCommon * /* stmt */
);
#endif /* XKBPARSE_H */ #endif /* XKBPARSE_H */

View File

@ -194,18 +194,30 @@ XkbMapConfig : OptFlags FileType OptMapName OBRACE
CBRACE SEMI CBRACE SEMI
{ {
if ($2 == XkmGeometryIndex) if ($2 == XkmGeometryIndex)
{
free($3);
FreeStmt($5);
$$= NULL; $$= NULL;
}
else else
{
$$= CreateXKBFile($2,$3,$5,$1); $$= CreateXKBFile($2,$3,$5,$1);
}
} }
; ;
XkbConfig : OptFlags FileType OptMapName DeclList XkbConfig : OptFlags FileType OptMapName DeclList
{ {
if ($2 == XkmGeometryIndex) if ($2 == XkmGeometryIndex)
{
free($3);
FreeStmt($4);
$$= NULL; $$= NULL;
}
else else
{
$$= CreateXKBFile($2,$3,$4,$1); $$= CreateXKBFile($2,$3,$4,$1);
}
} }
; ;
@ -455,11 +467,11 @@ SectionBody : SectionBody SectionBodyItem
SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
{ $$= NULL; } { $$= NULL; }
| VarDecl | VarDecl
{ $$= NULL; } { FreeStmt(&$1->common); $$= NULL; }
| DoodadDecl | DoodadDecl
{ $$= NULL; } { $$= NULL; }
| IndicatorMapDecl | IndicatorMapDecl
{ $$= NULL; } { FreeStmt(&$1->common); $$= NULL; }
| OverlayDecl | OverlayDecl
{ $$= NULL; } { $$= NULL; }
; ;
@ -473,7 +485,7 @@ RowBody : RowBody RowBodyItem
RowBodyItem : KEYS OBRACE Keys CBRACE SEMI RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
{ $$= NULL; } { $$= NULL; }
| VarDecl | VarDecl
{ $$= NULL; } { FreeStmt(&$1->common); $$= NULL; }
; ;
Keys : Keys COMMA Key Keys : Keys COMMA Key
@ -483,9 +495,9 @@ Keys : Keys COMMA Key
; ;
Key : KeyName Key : KeyName
{ $$= NULL; } { free($1); $$= NULL; }
| OBRACE ExprList CBRACE | OBRACE ExprList CBRACE
{ $$= NULL; } { FreeStmt(&$2->common); $$= NULL; }
; ;
OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
@ -493,15 +505,13 @@ OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
; ;
OverlayKeyList : OverlayKeyList COMMA OverlayKey OverlayKeyList : OverlayKeyList COMMA OverlayKey
{ { $$= NULL; }
$$= NULL;
}
| OverlayKey | OverlayKey
{ $$= NULL; } { $$= NULL; }
; ;
OverlayKey : KeyName EQUALS KeyName OverlayKey : KeyName EQUALS KeyName
{ $$= NULL; } { free($1); free($3); $$= NULL; }
; ;
OutlineList : OutlineList COMMA OutlineInList OutlineList : OutlineList COMMA OutlineInList
@ -515,7 +525,7 @@ OutlineInList : OBRACE CoordList CBRACE
| Ident EQUALS OBRACE CoordList CBRACE | Ident EQUALS OBRACE CoordList CBRACE
{ $$= NULL; } { $$= NULL; }
| Ident EQUALS Expr | Ident EQUALS Expr
{ $$= NULL; } { FreeStmt(&$3->common); $$= NULL; }
; ;
CoordList : CoordList COMMA Coord CoordList : CoordList COMMA Coord
@ -529,7 +539,7 @@ Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
; ;
DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
{ $$= NULL; } { FreeStmt(&$4->common); $$= NULL; }
; ;
DoodadType : TEXT { $$= 0; } DoodadType : TEXT { $$= 0; }