apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Poirier <poir...@pobox.com>
Subject Re: apr_env_set use of putenv
Date Wed, 14 Apr 2010 18:42:49 GMT
On 2010-03-29 at 09:54, Graham Leggett <minfrin@sharp.fm> wrote:

> From what I can see of the code right now, the caller is expected to
> control the lifetime of the string that it passes, or set up their own
> cleanup as appropriate to ensure that the environment entry is removed
> if the pool is removed.
>
> The strdup() is by definition a leak, so that isn't ideal at all.
>
> I suspect the docs would need to be updated to warn the caller than if
> they set a string in the environment, they are required to ensure
> their string lives as long as the process, or to register their own
> cleanup if not.

How about something like this:

Index: apr_env.h
===================================================================
--- apr_env.h	(revision 932940)
+++ apr_env.h	(working copy)
@@ -46,7 +46,10 @@
  * Set the value of an environment variable
  * @param envvar the name of the environment variable
  * @param value the value to set
- * @param pool where to allocate temporary storage from
+ * @param pool where to allocate storage from
+ * @remark The pool lifetime must be at least as long as the variable is
+ * in the environment, or the environment could be corrupted when the
+ * pool is destroyed.
  */
 APR_DECLARE(apr_status_t) apr_env_set(const char *envvar, const char *value,
                                       apr_pool_t *pool);


Mime
View raw message