]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgtop: use automatic clean-up
authorLennart Poettering <lennart@poettering.net>
Thu, 15 Nov 2018 19:07:45 +0000 (20:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 16 Nov 2018 13:46:49 +0000 (14:46 +0100)
src/cgtop/cgtop.c

index 69a5fde7322f3e67d879f0a9b560537e5611d9f6..cf2de7eb5a8d111445fc64f9e7dd15a6428cd863 100644 (file)
@@ -98,6 +98,8 @@ static void group_hashmap_free(Hashmap *h) {
         hashmap_free(h);
 }
 
+DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, group_hashmap_free);
+
 static const char *maybe_format_bytes(char *buf, size_t l, bool is_valid, uint64_t t) {
         if (!is_valid)
                 return "-";
@@ -924,13 +926,13 @@ static const char* counting_what(void) {
 }
 
 int main(int argc, char *argv[]) {
-        int r;
-        Hashmap *a = NULL, *b = NULL;
+        _cleanup_(group_hashmap_freep) Hashmap *a = NULL, *b = NULL;
         unsigned iteration = 0;
         usec_t last_refresh = 0;
         bool quit = false, immediate_refresh = false;
         _cleanup_free_ char *root = NULL;
         CGroupMask mask;
+        int r;
 
         log_parse_environment();
         log_open();
@@ -1138,8 +1140,6 @@ int main(int argc, char *argv[]) {
         r = 0;
 
 finish:
-        group_hashmap_free(a);
-        group_hashmap_free(b);
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }