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.
This commit is contained in:
Thomas Haller 2021-06-08 13:32:29 +02:00
parent c87433ebd2
commit 7825609f1f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1326,8 +1326,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);
}
}