From 889a299e3bb498427f96a4b354cc0ba5d560132a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 2 Mar 2012 14:49:36 +0200 Subject: [PATCH] Free XkbFile's when no longer needed Signed-off-by: Ran Benita --- src/xkbcomp/compat.c | 2 ++ src/xkbcomp/geometry.c | 3 +++ src/xkbcomp/keycodes.c | 3 +++ src/xkbcomp/keymap.c | 5 ++++- src/xkbcomp/keytypes.c | 3 +++ src/xkbcomp/misc.c | 19 +++++++++++++++---- src/xkbcomp/parseutils.c | 21 ++++++++------------- src/xkbcomp/symbols.c | 2 ++ src/xkbcomp/xkbcomp.c | 6 ++++-- 9 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index eb153ff..6dcabbc 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -426,6 +426,7 @@ HandleIncludeCompatMap(IncludeStmt * stmt, included.name = stmt->stmt; stmt->stmt = NULL; } + FreeXKBFile(rtrn); } else { @@ -459,6 +460,7 @@ HandleIncludeCompatMap(IncludeStmt * stmt, (*hndlr) (rtrn, xkb, MergeOverride, &next_incl); MergeIncludedCompatMaps(&included, &next_incl, op); ClearCompatInfo(&next_incl, xkb); + FreeXKBFile(rtrn); } else { diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c index f1de745..b90b595 100644 --- a/src/xkbcomp/geometry.c +++ b/src/xkbcomp/geometry.c @@ -35,6 +35,7 @@ #include "action.h" #include "keycodes.h" #include "alias.h" +#include "parseutils.h" #define DFLT_FONT "helvetica" #define DFLT_SLANT "r" @@ -1323,6 +1324,7 @@ HandleIncludeGeometry(IncludeStmt * stmt, struct xkb_desc * xkb, GeometryInfo * included.name = stmt->stmt; stmt->stmt = NULL; } + FreeXKBFile(rtrn); } else { @@ -1353,6 +1355,7 @@ HandleIncludeGeometry(IncludeStmt * stmt, struct xkb_desc * xkb, GeometryInfo * (*hndlr) (rtrn, xkb, MergeOverride, &next_incl); MergeIncludedGeometry(&included, &next_incl, op); ClearGeometryInfo(&next_incl); + FreeXKBFile(rtrn); } else { diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index ee76f4c..fe97d62 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -31,6 +31,7 @@ #include "keycodes.h" #include "misc.h" #include "alias.h" +#include "parseutils.h" const char * longText(unsigned long val) @@ -575,6 +576,7 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo * included.name = stmt->stmt; stmt->stmt = NULL; } + FreeXKBFile(rtrn); } else { @@ -602,6 +604,7 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo * HandleKeycodesFile(rtrn, xkb, MergeOverride, &next_incl); MergeIncludedKeycodes(&included, &next_incl, op); ClearKeyNamesInfo(&next_incl); + FreeXKBFile(rtrn); } else { diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c index b610431..9221852 100644 --- a/src/xkbcomp/keymap.c +++ b/src/xkbcomp/keymap.c @@ -83,7 +83,10 @@ CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge) /* Check for duplicate entries in the input file */ while ((file) && (ok)) { - file->topName = mainName; + if (file->topName != mainName) { + free(file->topName); + file->topName = strdup(mainName); + } if ((have & (1 << file->type)) != 0) { ERROR("More than one %s section in a %s file\n", diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 98ae2ec..fd49271 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -31,6 +31,7 @@ #include "vmod.h" #include "action.h" #include "misc.h" +#include "parseutils.h" typedef struct _PreserveInfo { @@ -390,6 +391,7 @@ HandleIncludeKeyTypes(IncludeStmt * stmt, included.name = stmt->stmt; stmt->stmt = NULL; } + FreeXKBFile(rtrn); } else { @@ -418,6 +420,7 @@ HandleIncludeKeyTypes(IncludeStmt * stmt, (*hndlr) (rtrn, xkb, op, &next_incl); MergeIncludedKeyTypes(&included, &next_incl, op, xkb); FreeKeyTypesInfo(&next_incl); + FreeXKBFile(rtrn); } else { diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c index 523614f..2f1fdd9 100644 --- a/src/xkbcomp/misc.c +++ b/src/xkbcomp/misc.c @@ -53,7 +53,7 @@ ProcessIncludeFile(IncludeStmt * stmt, XkbFile ** file_rtrn, unsigned *merge_rtrn) { FILE *file; - XkbFile *rtrn, *mapToUse; + XkbFile *rtrn, *mapToUse, *next; char oldFile[1024] = {0}; int oldLine = lineNum; @@ -85,10 +85,21 @@ ProcessIncludeFile(IncludeStmt * stmt, mapToUse = rtrn; if (stmt->map != NULL) { - while ((mapToUse) && ((!uStringEqual(mapToUse->name, stmt->map)) || - (mapToUse->type != file_type))) + while (mapToUse) { - mapToUse = (XkbFile *) mapToUse->common.next; + next = (XkbFile *)mapToUse->common.next; + mapToUse->common.next = NULL; + if (uStringEqual(mapToUse->name, stmt->map) && + mapToUse->type == file_type) + { + FreeXKBFile(next); + break; + } + else + { + FreeXKBFile(mapToUse); + } + mapToUse = next; } if (!mapToUse) { diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c index 158dc13..b88a1c2 100644 --- a/src/xkbcomp/parseutils.c +++ b/src/xkbcomp/parseutils.c @@ -633,6 +633,9 @@ LookupKeysym(char *str, uint32_t * sym_rtrn) return 0; } +static void +FreeInclude(IncludeStmt *incl); + IncludeStmt * IncludeCreate(char *str, unsigned merge) { @@ -696,20 +699,11 @@ IncludeCreate(char *str, unsigned merge) else free(stmt); return first; - BAIL: + +BAIL: ERROR("Illegal include statement \"%s\"\n", stmt); ACTION("Ignored\n"); - while (first) - { - incl = first->next; - free(first->file); - free(first->map); - free(first->modifier); - free(first->path); - first->file = first->map = first->path = NULL; - free(first); - first = incl; - } + FreeInclude(first); free(stmt); return NULL; } @@ -873,6 +867,7 @@ FreeStmt(ParseCommon *stmt) { case StmtInclude: FreeInclude((IncludeStmt *)stmt); + /* stmt is already free'd here. */ stmt = NULL; break; case StmtExpr: @@ -967,7 +962,7 @@ FreeXKBFile(XkbFile *file) } free(file->name); - /* free(file->topName); */ + free(file->topName); free(file); file = next; } diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 9ddcefa..416447e 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -777,6 +777,7 @@ HandleIncludeSymbols(IncludeStmt * stmt, included.name = stmt->stmt; stmt->stmt = NULL; } + FreeXKBFile(rtrn); } else { @@ -813,6 +814,7 @@ HandleIncludeSymbols(IncludeStmt * stmt, (*hndlr) (rtrn, xkb, MergeOverride, &next_incl); MergeIncludedSymbols(&included, &next_incl, op, xkb); FreeSymbolsInfo(&next_incl); + FreeXKBFile(rtrn); } else { diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c index e079d60..c72af74 100644 --- a/src/xkbcomp/xkbcomp.c +++ b/src/xkbcomp/xkbcomp.c @@ -225,11 +225,12 @@ xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg) goto unwind_xkb; } + FreeXKBFile(file); return xkb; unwind_xkb: XkbcFreeKeyboard(xkb); unwind_file: - /* XXX: here's where we would free the XkbFile */ + FreeXKBFile(file); fail: return NULL; } @@ -265,11 +266,12 @@ compile_keymap(XkbFile *file, const char *mapName) goto unwind_xkb; } + FreeXKBFile(file); return xkb; unwind_xkb: XkbcFreeKeyboard(xkb); unwind_file: - /* XXX: here's where we would free the XkbFile */ + FreeXKBFile(file); return NULL; } -- 2.7.4