From bd7cbd57704233669b248b035391919272aa2edc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Jun 2021 13:32:29 +0200 Subject: [PATCH] glib-aux/tests: avoid coverity warning in test_nm_g_source_sentinel() Coverity wrongly think there is a use after free in the test: Error: USE_AFTER_FREE (CWE-416): [#def559] [important] NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1305: alias: Assigning: "s1" = "_s". Now both point to the same storage. NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1324: freed_arg: "g_source_unref" frees "s1". NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1330: deref_after_free: Dereferencing freed pointer "s1". # 1328| s2 = nm_g_source_sentinel_get(0); # 1329| g_assert(s2 == s1); # 1330|-> g_assert_cmpint(g_atomic_int_get(&s1->ref_count), >=, 1); # 1331| } # 1332| } Rework the code in the hope to avoid the false warning. (cherry picked from commit 7825609f1f7bb0a0ea710a2fddba426f30a519de) (cherry picked from commit c47c823c9dad6fb61014a71510b76ed82e72be84) --- shared/nm-glib-aux/tests/test-shared-general.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/tests/test-shared-general.c b/shared/nm-glib-aux/tests/test-shared-general.c index 3bf63d6df2..a6ad8dffdc 100644 --- a/shared/nm-glib-aux/tests/test-shared-general.c +++ b/shared/nm-glib-aux/tests/test-shared-general.c @@ -1289,8 +1289,8 @@ test_nm_g_source_sentinel(void) if (nmtst_get_rand_bool()) { s2 = nm_g_source_sentinel_get(0); + g_assert_cmpint(g_atomic_int_get(&s2->ref_count), >=, 1); g_assert(s2 == s1); - g_assert_cmpint(g_atomic_int_get(&s1->ref_count), >=, 1); } }