Free all atoms along with keymap The code to do this is taken from xserver, dix/atom.c. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/src/atom.c b/src/atom.c
index 8f9aa0d..09ff9ad 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -215,3 +215,26 @@ xkb_intern_atom(const char *string)
else
return None;
}
+
+static void
+FreeAtom(NodePtr patom)
+{
+ if (patom->left)
+ FreeAtom(patom->left);
+ if (patom->right)
+ FreeAtom(patom->right);
+ free(patom->string);
+ free(patom);
+}
+
+void
+XkbcFreeAllAtoms(void)
+{
+ if (atomRoot == NULL)
+ return;
+ FreeAtom(atomRoot);
+ atomRoot = NULL;
+ free(nodeTable);
+ nodeTable = NULL;
+ lastAtom = None;
+}
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 50d3707..cee6856 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -29,6 +29,7 @@ authorization from the authors.
#include "xkballoc.h"
#include "xkbrules.h"
#include "xkbpath.h"
+#include "xkbmisc.h"
#include "parseutils.h"
#include "utils.h"
@@ -315,4 +316,5 @@ void
xkb_free_keymap(struct xkb_desc *xkb)
{
XkbcFreeKeyboard(xkb);
+ XkbcFreeAllAtoms();
}
diff --git a/src/xkbmisc.h b/src/xkbmisc.h
index 40f1334..4673f0d 100644
--- a/src/xkbmisc.h
+++ b/src/xkbmisc.h
@@ -70,6 +70,9 @@ XkbcNameMatchesPattern(char *name, char *ptrn);
extern char *
XkbcAtomGetString(uint32_t atom);
+extern void
+XkbcFreeAllAtoms(void);
+
/***====================================================================***/
extern const char *