summaryrefslogtreecommitdiff
path: root/src/timedate/timedatectl.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/timedate/timedatectl.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/timedate/timedatectl.c')
-rw-r--r--src/timedate/timedatectl.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 61b6e765c7..195d5f3892 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -73,6 +73,13 @@ typedef struct StatusInfo {
bool ntp_synced;
} StatusInfo;
+static void status_info_clear(StatusInfo *info) {
+ if (info) {
+ free(info->timezone);
+ zero(*info);
+ }
+}
+
static void print_status_info(const StatusInfo *i) {
char a[FORMAT_TIMESTAMP_MAX];
struct tm tm;
@@ -155,7 +162,7 @@ static void print_status_info(const 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[] = {
{ "Timezone", "s", NULL, offsetof(StatusInfo, timezone) },
{ "LocalRTC", "b", NULL, offsetof(StatusInfo, rtc_local) },
@@ -175,15 +182,11 @@ static int show_status(sd_bus *bus, char **args, unsigned n) {
"/org/freedesktop/timedate1",
map,
&info);
- if (r < 0) {
- log_error_errno(r, "Failed to query server: %m");
- goto fail;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to query server: %m");
print_status_info(&info);
-fail:
- free(info.timezone);
return r;
}