From: Valentine Krasnobaeva Date: Thu, 26 Jun 2025 14:49:12 +0000 (+0200) Subject: BUG/MINOR: tools: use my_unsetenv instead of unsetenv X-Git-Tag: v3.3-dev2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9afc10ae8741ac34bc049856de46d2891b7be27;p=thirdparty%2Fhaproxy.git BUG/MINOR: tools: use my_unsetenv instead of unsetenv Let's use our own implementation of unsetenv() instead of the one, which is provided in libc. Implementation from libc may vary in dependency of UNIX distro. Implemenation from libc.so.1 ported on Illumos (see the link below) has caused an eternal loop in the clean_env(), where we invoke unsetenv(). (https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getenv.c#L411C1-L456C1) This is reported at GitHUB #3018 and the reporter has proposed the patch, which we really appreciate! But looking at his fix and to the implementations of unsetenv() in FreeBSD libc and in Linux glibc 2.31, it seems, that the algorithm of clean_env() will perform better with our my_unsetenv() implementation. This should be backported in versions 3.1 and 3.2. --- diff --git a/src/tools.c b/src/tools.c index 731d8f93c..4507564bc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -7147,7 +7147,7 @@ int backup_env(void) * doesn't contain "=" (the latter is mandatory format for strings kept in * **environ). This allows to terminate the process at the startup stage, if it * was launched in zero-warning mode and there are some problems with - * environment. + * environment. It's not thread-safe as uses my_unsetenv, which is not thread-safe. */ int clean_env(void) { @@ -7172,9 +7172,8 @@ int clean_env(void) return -1; } - if (unsetenv(name) != 0) - ha_warning("unsetenv() fails for '%s': %s.\n", - name, strerror(errno)); + my_unsetenv(name); + free(name); }