Free XkbFile's when no longer needed
authorRan Benita <ran234@gmail.com>
Fri, 2 Mar 2012 12:49:36 +0000 (14:49 +0200)
committerRan Benita <ran234@gmail.com>
Sat, 3 Mar 2012 22:04:04 +0000 (00:04 +0200)
Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/compat.c
src/xkbcomp/geometry.c
src/xkbcomp/keycodes.c
src/xkbcomp/keymap.c
src/xkbcomp/keytypes.c
src/xkbcomp/misc.c
src/xkbcomp/parseutils.c
src/xkbcomp/symbols.c
src/xkbcomp/xkbcomp.c

index eb153ff..6dcabbc 100644 (file)
@@ -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
             {
index f1de745..b90b595 100644 (file)
@@ -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
             {
index ee76f4c..fe97d62 100644 (file)
@@ -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
             {
index b610431..9221852 100644 (file)
@@ -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",
index 98ae2ec..fd49271 100644 (file)
@@ -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
             {
index 523614f..2f1fdd9 100644 (file)
@@ -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)
         {
index 158dc13..b88a1c2 100644 (file)
@@ -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;
     }
index 9ddcefa..416447e 100644 (file)
@@ -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
             {
index e079d60..c72af74 100644 (file)
@@ -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;
 }