From 20c6fa62a709a4d54c627761134351bc8bbf83e8 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Tue, 21 Nov 2023 08:50:38 +0100 Subject: [PATCH] registry: Use `steal` for better memory handling --- meson.build | 1 + src/registry.c | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index d5c4c74e4..ded142f72 100644 --- a/meson.build +++ b/meson.build @@ -364,6 +364,7 @@ if get_option('enable-xkbregistry') 'src/utils.c', 'src/util-list.h', 'src/util-list.c', + 'src/util-mem.h', ] libxkbregistry_link_args = [] libxkbregistry_link_deps = [] diff --git a/src/registry.c b/src/registry.c index cd1560e7e..19b2b36c4 100644 --- a/src/registry.c +++ b/src/registry.c @@ -34,6 +34,7 @@ #include "xkbcommon/xkbregistry.h" #include "utils.h" #include "util-list.h" +#include "util-mem.h" struct rxkb_object; @@ -803,9 +804,9 @@ parse_model(struct rxkb_context *ctx, xmlNode *model, /* new model */ m = rxkb_model_create(&ctx->base); - m->name = config.name; - m->description = config.description; - m->vendor = config.vendor; + m->name = steal(&config.name); + m->description = steal(&config.description); + m->vendor = steal(&config.vendor); m->popularity = config.popularity; list_append(&ctx->models, &m->base.link); } @@ -894,10 +895,10 @@ parse_variant(struct rxkb_context *ctx, struct rxkb_layout *l, list_init(&v->iso639s); list_init(&v->iso3166s); v->name = strdup(l->name); - v->variant = config.name; - v->description = config.description; + v->variant = steal(&config.name); + v->description = steal(&config.description); // if variant omits brief, inherit from parent layout. - v->brief = config.brief == NULL ? strdup_safe(l->brief) : config.brief; + v->brief = config.brief == NULL ? strdup_safe(l->brief) : steal(&config.brief); v->popularity = config.popularity; list_append(&ctx->layouts, &v->base.link); @@ -979,10 +980,10 @@ parse_layout(struct rxkb_context *ctx, xmlNode *layout, l = rxkb_layout_create(&ctx->base); list_init(&l->iso639s); list_init(&l->iso3166s); - l->name = config.name; + l->name = steal(&config.name); l->variant = NULL; - l->description = config.description; - l->brief = config.brief; + l->description = steal(&config.description); + l->brief = steal(&config.brief); l->popularity = config.popularity; list_append(&ctx->layouts, &l->base.link); } else { @@ -1034,8 +1035,8 @@ parse_option(struct rxkb_context *ctx, struct rxkb_option_group *group, } o = rxkb_option_create(&group->base); - o->name = config.name; - o->description = config.description; + o->name = steal(&config.name); + o->description = steal(&config.description); o->popularity = config.popularity; list_append(&group->options, &o->base.link); } @@ -1063,8 +1064,8 @@ parse_group(struct rxkb_context *ctx, xmlNode *group, if (!exists) { g = rxkb_option_group_create(&ctx->base); - g->name = config.name; - g->description = config.description; + g->name = steal(&config.name); + g->description = steal(&config.description); g->popularity = config.popularity; multiple = xmlGetProp(group, (const xmlChar*)"allowMultipleSelection");