summaryrefslogtreecommitdiff
path: root/src/locale/localectl.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-06-14 15:08:52 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2015-06-14 15:08:52 +0200
commite7e55dbdc38f929805ab2407fbd50886043a9e7c (patch)
tree8b159323816ae571765dbbd883f3f0d7a0ba3a4e /src/locale/localectl.c
parentaa75494ad5cdf7bede947212ad8c8356d78580fa (diff)
tree-wide: fix memory leaks in users of bus_map_all_properties()
If you use bus_map_all_properties(), you must be aware that it might touch output variables even though it may fail. This is, because we parse many different bus-properties and cannot tell how to clean them up, in case we fail deep down in the parser. Fix all callers of bus_map_all_properties() to correctly cleanup any context structures at all times.
Diffstat (limited to 'src/locale/localectl.c')
-rw-r--r--src/locale/localectl.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 8c60339e3e..601839d5dc 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -69,14 +69,27 @@ static void polkit_agent_open_if_enabled(void) {
typedef struct StatusInfo {
char **locale;
- const char *vconsole_keymap;
- const char *vconsole_keymap_toggle;
- const char *x11_layout;
- const char *x11_model;
- const char *x11_variant;
- const char *x11_options;
+ char *vconsole_keymap;
+ char *vconsole_keymap_toggle;
+ char *x11_layout;
+ char *x11_model;
+ char *x11_variant;
+ char *x11_options;
} StatusInfo;
+static void status_info_clear(StatusInfo *info) {
+ if (info) {
+ strv_free(info->locale);
+ free(info->vconsole_keymap);
+ free(info->vconsole_keymap_toggle);
+ free(info->x11_layout);
+ free(info->x11_model);
+ free(info->x11_variant);
+ free(info->x11_options);
+ zero(*info);
+ }
+}
+
static void print_overridden_variables(void) {
int r;
char *variables[_VARIABLE_LC_MAX] = {};
@@ -150,7 +163,7 @@ static void print_status_info(StatusInfo *i) {
}
static int show_status(sd_bus *bus, char **args, unsigned n) {
- StatusInfo info = {};
+ _cleanup_(status_info_clear) StatusInfo info = {};
static const struct bus_properties_map map[] = {
{ "VConsoleKeymap", "s", NULL, offsetof(StatusInfo, vconsole_keymap) },
{ "VConsoleKeymap", "s", NULL, offsetof(StatusInfo, vconsole_keymap) },
@@ -171,16 +184,12 @@ static int show_status(sd_bus *bus, char **args, unsigned n) {
"/org/freedesktop/locale1",
map,
&info);
- if (r < 0) {
- log_error_errno(r, "Could not get properties: %m");
- goto fail;
- }
+ if (r < 0)
+ return log_error_errno(r, "Could not get properties: %m");
print_overridden_variables();
print_status_info(&info);
-fail:
- strv_free(info.locale);
return r;
}