xkbcomp: Use `steal` for better memory handling
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
diff --git a/meson.build b/meson.build
index ded142f..25b9ef6 100644
--- a/meson.build
+++ b/meson.build
@@ -228,6 +228,7 @@ libxkbcommon_sources = [
'src/text.h',
'src/utf8.c',
'src/utf8.h',
+ 'src/util-mem.h',
'src/utils.c',
'src/utils.h',
]
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 1df9e03..bb45c69 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -55,6 +55,7 @@
#include "action.h"
#include "vmod.h"
#include "include.h"
+#include "util-mem.h"
enum si_field {
SI_FIELD_VIRTUAL_MOD = (1 << 0),
@@ -393,8 +394,7 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
into->mods = from->mods;
if (into->name == NULL) {
- into->name = from->name;
- from->name = NULL;
+ into->name = steal(&from->name);
}
if (darray_empty(into->interps)) {
@@ -440,8 +440,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
InitCompatInfo(&included, info->ctx, 0 /* unused */,
info->actions, &info->mods);
- included.name = include->stmt;
- include->stmt = NULL;
+ included.name = steal(&include->stmt);
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
CompatInfo next_incl;
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 700cd1c..3e3254d 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -30,6 +30,7 @@
#include "text.h"
#include "expr.h"
#include "include.h"
+#include "util-mem.h"
typedef struct {
enum merge_mode merge;
@@ -268,8 +269,7 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
}
if (into->name == NULL) {
- into->name = from->name;
- from->name = NULL;
+ into->name = steal(&from->name);
}
/* Merge key names. */
@@ -348,8 +348,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *include)
}
InitKeyNamesInfo(&included, info->ctx, 0 /* unused */);
- included.name = include->stmt;
- include->stmt = NULL;
+ included.name = steal(&include->stmt);
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyNamesInfo next_incl;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 0c4fbeb..4492a73 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -60,6 +60,7 @@
#include "vmod.h"
#include "include.h"
#include "keysym.h"
+#include "util-mem.h"
enum key_repeat {
@@ -518,8 +519,7 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
into->mods = from->mods;
if (into->name == NULL) {
- into->name = from->name;
- from->name = NULL;
+ into->name = steal(&from->name);
}
group_names_in_both = MIN(darray_size(into->group_names),
@@ -579,8 +579,7 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include)
InitSymbolsInfo(&included, info->keymap, 0 /* unused */,
info->actions, &info->mods);
- included.name = include->stmt;
- include->stmt = NULL;
+ included.name = steal(&include->stmt);
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
SymbolsInfo next_incl;
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index f22c9ef..404bfea 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -31,6 +31,7 @@
#include "vmod.h"
#include "expr.h"
#include "include.h"
+#include "util-mem.h"
enum type_field {
TYPE_FIELD_MASK = (1 << 0),
@@ -192,8 +193,7 @@ MergeIncludedKeyTypes(KeyTypesInfo *into, KeyTypesInfo *from,
into->mods = from->mods;
if (into->name == NULL) {
- into->name = from->name;
- from->name = NULL;
+ into->name = steal(&from->name);
}
if (darray_empty(into->types)) {
@@ -228,8 +228,7 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *include)
}
InitKeyTypesInfo(&included, info->ctx, 0 /* unused */, &info->mods);
- included.name = include->stmt;
- include->stmt = NULL;
+ included.name = steal(&include->stmt);
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyTypesInfo next_incl;