systemd/tests: avoid using g_free() with buffers allocated with malloc() in _test_unbase64mem_mem()

Coverity says:

  Error: ALLOC_FREE_MISMATCH (CWE-762):
  NetworkManager-1.31.3/src/core/tests/test-systemd.c:261: alloc: Allocation of memory which must be freed using "free".
  NetworkManager-1.31.3/src/core/tests/test-systemd.c:274: free: Calling "_nm_auto_g_free" frees "exp2_arr" using "g_free" but it should have been freed using "free".
  #  272|           g_assert_cmpmem(expected_arr, expected_len, exp3_arr, exp3_len);
  #  273|       }
  #  274|-> }
  #  275|
  #  276|   #define _test_unbase64mem(base64, expected_str) \

  Error: ALLOC_FREE_MISMATCH (CWE-762):
  NetworkManager-1.31.3/src/core/tests/test-systemd.c:270: alloc: Allocation of memory which must be freed using "free".
  NetworkManager-1.31.3/src/core/tests/test-systemd.c:274: free: Calling "_nm_auto_g_free" frees "exp3_arr" using "g_free" but it should have been freed using "free".
  #  272|           g_assert_cmpmem(expected_arr, expected_len, exp3_arr, exp3_len);
  #  273|       }
  #  274|-> }
  #  275|
  #  276|   #define _test_unbase64mem(base64, expected_str) \

Fixes: 0298d54078 ('systemd: expose unbase64mem() as nm_sd_utils_unbase64mem()')
(cherry picked from commit 44abe6d661)
(cherry picked from commit d2d343289d)
This commit is contained in:
Thomas Haller 2021-05-06 19:13:43 +02:00
parent 023c6a66d9
commit 76ef3efdff
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -247,11 +247,11 @@ _test_unbase64mem_mem(const char *base64, const guint8 *expected_arr, gsize expe
{
gs_free char *expected_base64 = NULL;
int r;
gs_free guint8 *exp2_arr = NULL;
gs_free guint8 *exp3_arr = NULL;
gsize exp2_len;
gsize exp3_len;
gsize i;
nm_auto_free guint8 *exp2_arr = NULL;
nm_auto_free guint8 *exp3_arr = NULL;
gsize exp2_len;
gsize exp3_len;
gsize i;
expected_base64 = g_base64_encode(expected_arr, expected_len);