registry: 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
diff --git a/meson.build b/meson.build
index d5c4c74..ded142f 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 cd1560e..19b2b36 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");