Before this patch, the code executed on Linux used `putenv`, which
requires a memory allocation. However, the memory was explicitly freed
only for Windows (`__MINGW32__`) and older VxWorks targets. Because
Linux fell into the allocation block but not the free block, there
was a memory leak.
To fix the leak, `__gnat_setenv` now calls `setenv` for Linux, doing
the same thing we were already doing for macOS.
Note that putting Linux in the Windows block is not a solution because,
on Linux, `putenv` uses the pointer directly and does not copy the
string. Therefore, if the memory were freed right away, there would be
a use-after-free.
To be careful, we do not use `setenv` everywhere else (except for old
VxWorks targets and Windows), because there might be problems with other
configurations if we do so.
gcc/ada/ChangeLog:
* env.c (__gnat_setenv): Add __linux__ preprocessor macro
directive to the setenv block.
__gnat_setenv (char *name, char *value)
{
#if (defined (__vxworks) && (defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7)) \
- || defined (__APPLE__)
+ || defined (__APPLE__) \
+ || defined (__linux__)
setenv (name, value, 1);
-#else
+#else /* Why don't we use setenv on all platforms where it's available??? */
size_t size = strlen (name) + strlen (value) + 2;
char *expression;