diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2024-03-31 12:14:04 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2024-04-04 20:12:03 +0200 |
commit | 5f5b21fd5cbf9ef3d19d3a5f1eb24bdc301bbbd7 (patch) | |
tree | 3e31467e0d87ef6a941670fac8ef2bb77313534c | |
parent | f7fe4c59781fde33e112be2cfdec44b84fda6497 (diff) |
lib/env.c: treat out of memory condition as error
If not enough memory is available for more environment variables, treat
it exactly like not enough memory for new environment variable content.
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r-- | lib/env.c | 30 |
1 files changed, 9 insertions, 21 deletions
@@ -127,30 +127,18 @@ void addenv (const char *string, /*@null@*/const char *value) if ((newenvc & (NEWENVP_STEP - 1)) == 0) { bool update_environ; - char **__newenvp; - /* - * If the resize operation succeeds we can - * happily go on, else print a message. - */ update_environ = (environ == newenvp); - __newenvp = REALLOC(newenvp, newenvc + NEWENVP_STEP, char *); - - if (NULL != __newenvp) { - /* - * If this is our current environment, update - * environ so that it doesn't point to some - * free memory area (realloc() could move it). - */ - if (update_environ) - environ = __newenvp; - newenvp = __newenvp; - } else { - (void) fputs (_("Environment overflow\n"), log_get_logfd()); - newenvc--; - free (newenvp[newenvc]); - } + newenvp = XREALLOC(newenvp, newenvc + NEWENVP_STEP, char *); + + /* + * If this is our current environment, update + * environ so that it doesn't point to some + * free memory area (realloc() could move it). + */ + if (update_environ) + environ = newenvp; } /* |