]> git.ipfire.org Git - thirdparty/strongswan.git/commit
array: Don't use realloc() with zero size in array_compress()
authorThomas Egerer <thomas.egerer@secunet.com>
Fri, 6 Sep 2024 11:29:40 +0000 (13:29 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 12 Sep 2024 06:53:26 +0000 (08:53 +0200)
commitcf7fb47788dfb83bb5d8bd0bffdb582e381a2f0a
treee7b7a51fb5d84c24d239c0419082a6c86658f82d
parent957aae8f646d6e4e37d62efc505f2c6f7181c879
array: Don't use realloc() with zero size in array_compress()

The behavior of realloc(3) with zero size was apparently implementation
defined.  While glibc documents the behavior as equivalent to free(3),
that might not apply to other C libraries.  With C17, this behavior has
been deprecated, and with C23, the behavior is now undefined.  It's also
why valgrind warns about this use.

Hence, when array_compress() would call realloc() with a zero size, we
now call free() explicitly and set the pointer to NULL.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
src/libstrongswan/collections/array.c