加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0182-test-socket-util-avoid-memleak-reported-by-valgrind.patch 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
From fe6895fb6a5f8c61f0c47aa95e1c86bb88b7cf4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 21 Aug 2018 19:44:48 +0200
Subject: [PATCH] test-socket-util: avoid "memleak" reported by valgrind
valgrind reports the allocation done in the short-lived child as a leak.
Let's restructure the code to avoid this.
(cherry picked from commit 181c4ba750770b54a54b5abbe8ae8ff4f6db59b5)
Resolves: #1683319
---
src/test/test-socket-util.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index ac2ea52a5c..588485d881 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -431,7 +431,6 @@ static void test_getpeercred_getpeergroups(void) {
if (r == 0) {
static const gid_t gids[] = { 3, 4, 5, 6, 7 };
gid_t *test_gids;
- _cleanup_free_ gid_t *peer_groups = NULL;
size_t n_test_gids;
uid_t test_uid;
gid_t test_gid;
@@ -472,12 +471,16 @@ static void test_getpeercred_getpeergroups(void) {
assert_se(ucred.gid == test_gid);
assert_se(ucred.pid == getpid_cached());
- r = getpeergroups(pair[0], &peer_groups);
- assert_se(r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT));
+ {
+ _cleanup_free_ gid_t *peer_groups = NULL;
- if (r >= 0) {
- assert_se((size_t) r == n_test_gids);
- assert_se(memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0);
+ r = getpeergroups(pair[0], &peer_groups);
+ assert_se(r >= 0 || IN_SET(r, -EOPNOTSUPP, -ENOPROTOOPT));
+
+ if (r >= 0) {
+ assert_se((size_t) r == n_test_gids);
+ assert_se(memcmp(peer_groups, test_gids, sizeof(gid_t) * n_test_gids) == 0);
+ }
}
safe_close_pair(pair);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化