summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-10 01:45:20 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-10 01:45:20 +0200
commit6a6e9c039ff1576b53e92aed47f8527d4880116d (patch)
tree9b844c1246a15aba05f5f9a6a66e04bc45b4f6c3
parentlogind: fix borked r check (diff)
downloadsystemd-6a6e9c039ff1576b53e92aed47f8527d4880116d.tar.xz
systemd-6a6e9c039ff1576b53e92aed47f8527d4880116d.zip
localed: fix memleak in error path
CID #1390929.
-rw-r--r--src/locale/keymap-util.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index 09bd449925..1aca627658 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -530,9 +530,10 @@ int find_converted_keymap(const char *x11_layout, const char *x11_variant, char
return 0;
}
-int find_legacy_keymap(Context *c, char **new_keymap) {
+int find_legacy_keymap(Context *c, char **ret) {
const char *map;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *new_keymap = NULL;
unsigned n = 0;
unsigned best_matching = 0;
int r;
@@ -597,7 +598,7 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
if (matching > best_matching) {
best_matching = matching;
- r = free_and_strdup(new_keymap, a[0]);
+ r = free_and_strdup(&new_keymap, a[0]);
if (r < 0)
return r;
}
@@ -617,13 +618,12 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
r = find_converted_keymap(l, v, &converted);
if (r < 0)
return r;
- if (r > 0) {
- free(*new_keymap);
- *new_keymap = converted;
- }
+ if (r > 0)
+ free_and_replace(new_keymap, converted);
}
- return (bool) *new_keymap;
+ *ret = TAKE_PTR(new_keymap);
+ return (bool) *ret;
}
int find_language_fallback(const char *lang, char **language) {