summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.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/systemctl/systemctl.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/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5075e4e176..a2eb435fce 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1678,17 +1678,23 @@ static const struct bus_properties_map machine_info_property_map[] = {
{}
};
+static void machine_info_clear(struct machine_info *info) {
+ if (info) {
+ free(info->name);
+ free(info->state);
+ free(info->control_group);
+ zero(*info);
+ }
+}
+
static void free_machines_list(struct machine_info *machine_infos, int n) {
int i;
if (!machine_infos)
return;
- for (i = 0; i < n; i++) {
- free(machine_infos[i].name);
- free(machine_infos[i].state);
- free(machine_infos[i].control_group);
- }
+ for (i = 0; i < n; i++)
+ machine_info_clear(&machine_infos[i]);
free(machine_infos);
}
@@ -4402,7 +4408,7 @@ static int show_all(
static int show_system_status(sd_bus *bus) {
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
_cleanup_free_ char *hn = NULL;
- struct machine_info mi = {};
+ _cleanup_(machine_info_clear) struct machine_info mi = {};
const char *on, *off;
int r;
@@ -4449,9 +4455,6 @@ static int show_system_status(sd_bus *bus) {
show_cgroup(SYSTEMD_CGROUP_CONTROLLER, strempty(mi.control_group), prefix, c, false, get_output_flags());
}
- free(mi.state);
- free(mi.control_group);
-
return 0;
}