dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
4bff0a
From fe6895fb6a5f8c61f0c47aa95e1c86bb88b7cf4f Mon Sep 17 00:00:00 2001
4bff0a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
4bff0a
Date: Tue, 21 Aug 2018 19:44:48 +0200
4bff0a
Subject: [PATCH] test-socket-util: avoid "memleak" reported by valgrind
4bff0a
4bff0a
valgrind reports the allocation done in the short-lived child as a leak.
4bff0a
Let's restructure the code to avoid this.
4bff0a
4bff0a
(cherry picked from commit 181c4ba750770b54a54b5abbe8ae8ff4f6db59b5)
4bff0a
4bff0a
Resolves: #1683319
4bff0a
---
4bff0a
 src/test/test-socket-util.c | 15 +++++++++------
4bff0a
 1 file changed, 9 insertions(+), 6 deletions(-)
4bff0a
4bff0a
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
4bff0a
index ac2ea52a5c..588485d881 100644
4bff0a
--- a/src/test/test-socket-util.c
4bff0a
+++ b/src/test/test-socket-util.c
4bff0a
@@ -431,7 +431,6 @@ static void test_getpeercred_getpeergroups(void) {
4bff0a
         if (r == 0) {
4bff0a
                 static const gid_t gids[] = { 3, 4, 5, 6, 7 };
4bff0a
                 gid_t *test_gids;
4bff0a
-                _cleanup_free_ gid_t *peer_groups = NULL;
4bff0a
                 size_t n_test_gids;
4bff0a
                 uid_t test_uid;
4bff0a
                 gid_t test_gid;
4bff0a
@@ -472,12 +471,16 @@ static void test_getpeercred_getpeergroups(void) {
4bff0a
                 assert_se(ucred.gid == test_gid);
4bff0a
                 assert_se(ucred.pid == getpid_cached());
4bff0a
 
4bff0a
-                r = getpeergroups(pair[0], &peer_groups);
4bff0a
-                assert_se(r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT));
4bff0a
+                {
4bff0a
+                        _cleanup_free_ gid_t *peer_groups = NULL;
4bff0a
 
4bff0a
-                if (r >= 0) {
4bff0a
-                        assert_se((size_t) r == n_test_gids);
4bff0a
-                        assert_se(memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0);
4bff0a
+                        r = getpeergroups(pair[0], &peer_groups);
4bff0a
+                        assert_se(r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT));
4bff0a
+
4bff0a
+                        if (r >= 0) {
4bff0a
+                                assert_se((size_t) r == n_test_gids);
4bff0a
+                                assert_se(memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0);
4bff0a
+                        }
4bff0a
                 }
4bff0a
 
4bff0a
                 safe_close_pair(pair);