On 29 Mar 2010, at 3:36 PM, Dan Poirier wrote:

I don't think that's the right pattern to follow. apr_table is used to
allocate a new data structure, owned by the caller, and the caller
certainly should control its lifetime. apr_env_set() is used to add an
entry to the OS's environment, which the caller does not own and would
not expect to have any control over the lifetime of its entries.

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.

Regards,
Graham
--

Reply via email to