summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-03-31 12:14:04 +0200
committerAlejandro Colomar <alx@kernel.org>2024-04-04 20:12:03 +0200
commit5f5b21fd5cbf9ef3d19d3a5f1eb24bdc301bbbd7 (patch)
tree3e31467e0d87ef6a941670fac8ef2bb77313534c
parentf7fe4c59781fde33e112be2cfdec44b84fda6497 (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.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/lib/env.c b/lib/env.c
index f2d35d71..9b5fd32f 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -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;
}
/*