Simply maintain an internal mapping of the settings done through your f_system_putenv, and feed pointers to those strings to putenv(3). The strings will then stay referenced through the mapping, and be freed properly when entries for the same variables are replaced by later calls.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-10-17 18:35: Subject: Re: putenv/getenv
On Fri, 17 Oct 2003, Martin Stjernholm, Roxen IS @ Pike developers forum wrote:
Well, rather to a late enough moment. They can be popped only when you stopped referring to them. If the latest possible moment is before that, you have to restructure your code to solve it.
Tip: The macro stack_pop_n_elems_keep_top should always make it possible to postpone it to just before the return.
That's good to know. I'll keep it in mind. I'll just chalk my errors up to sloppiness due to lack of recent experience :)
what would be the best way to handle strings with NUL? Should they be changed or should an error be thrown? My guess is that an error should be thrown as you really wouldn't want them in the environment, right?
Yes, I think so too.
I've made the suggested changes up to the point of tracking the leaks. Anyone have thoughts about the best way to track them might be?
It'd be necessary to limit leaking according to Marcus' suggestion before you can do that, imo.
Bill
/ Brevbäraren