xkbcomp: Use `steal` for better memory handling

master
Pierre Le Marre 2023-11-23 09:30:57 +01:00 committed by Peter Hutterer
parent 20c6fa62a7
commit 20329baf4d
5 changed files with 13 additions and 16 deletions

View File

@ -228,6 +228,7 @@ libxkbcommon_sources = [
'src/text.h', 'src/text.h',
'src/utf8.c', 'src/utf8.c',
'src/utf8.h', 'src/utf8.h',
'src/util-mem.h',
'src/utils.c', 'src/utils.c',
'src/utils.h', 'src/utils.h',
] ]

View File

@ -55,6 +55,7 @@
#include "action.h" #include "action.h"
#include "vmod.h" #include "vmod.h"
#include "include.h" #include "include.h"
#include "util-mem.h"
enum si_field { enum si_field {
SI_FIELD_VIRTUAL_MOD = (1 << 0), SI_FIELD_VIRTUAL_MOD = (1 << 0),
@ -393,8 +394,7 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
into->mods = from->mods; into->mods = from->mods;
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = steal(&from->name);
from->name = NULL;
} }
if (darray_empty(into->interps)) { if (darray_empty(into->interps)) {
@ -440,8 +440,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
InitCompatInfo(&included, info->ctx, 0 /* unused */, InitCompatInfo(&included, info->ctx, 0 /* unused */,
info->actions, &info->mods); info->actions, &info->mods);
included.name = include->stmt; included.name = steal(&include->stmt);
include->stmt = NULL;
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) { for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
CompatInfo next_incl; CompatInfo next_incl;

View File

@ -30,6 +30,7 @@
#include "text.h" #include "text.h"
#include "expr.h" #include "expr.h"
#include "include.h" #include "include.h"
#include "util-mem.h"
typedef struct { typedef struct {
enum merge_mode merge; enum merge_mode merge;
@ -268,8 +269,7 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
} }
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = steal(&from->name);
from->name = NULL;
} }
/* Merge key names. */ /* Merge key names. */
@ -348,8 +348,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *include)
} }
InitKeyNamesInfo(&included, info->ctx, 0 /* unused */); InitKeyNamesInfo(&included, info->ctx, 0 /* unused */);
included.name = include->stmt; included.name = steal(&include->stmt);
include->stmt = NULL;
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) { for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyNamesInfo next_incl; KeyNamesInfo next_incl;

View File

@ -60,6 +60,7 @@
#include "vmod.h" #include "vmod.h"
#include "include.h" #include "include.h"
#include "keysym.h" #include "keysym.h"
#include "util-mem.h"
enum key_repeat { enum key_repeat {
@ -518,8 +519,7 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
into->mods = from->mods; into->mods = from->mods;
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = steal(&from->name);
from->name = NULL;
} }
group_names_in_both = MIN(darray_size(into->group_names), 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 */, InitSymbolsInfo(&included, info->keymap, 0 /* unused */,
info->actions, &info->mods); info->actions, &info->mods);
included.name = include->stmt; included.name = steal(&include->stmt);
include->stmt = NULL;
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) { for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
SymbolsInfo next_incl; SymbolsInfo next_incl;

View File

@ -31,6 +31,7 @@
#include "vmod.h" #include "vmod.h"
#include "expr.h" #include "expr.h"
#include "include.h" #include "include.h"
#include "util-mem.h"
enum type_field { enum type_field {
TYPE_FIELD_MASK = (1 << 0), TYPE_FIELD_MASK = (1 << 0),
@ -192,8 +193,7 @@ MergeIncludedKeyTypes(KeyTypesInfo *into, KeyTypesInfo *from,
into->mods = from->mods; into->mods = from->mods;
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = steal(&from->name);
from->name = NULL;
} }
if (darray_empty(into->types)) { if (darray_empty(into->types)) {
@ -228,8 +228,7 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *include)
} }
InitKeyTypesInfo(&included, info->ctx, 0 /* unused */, &info->mods); InitKeyTypesInfo(&included, info->ctx, 0 /* unused */, &info->mods);
included.name = include->stmt; included.name = steal(&include->stmt);
include->stmt = NULL;
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) { for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
KeyTypesInfo next_incl; KeyTypesInfo next_incl;