This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: clearenv for newlib


Joel Sherrill wrote:
Hi,

I am porting a library to RTEMS that is calling clearenv().
I am willing to implement one for newlib.  Is this a
method OK for newlib to have?

I was looking at the current environ code to gauge the
difficulty and noticed that unsetenv() does not free
any memory.  Since putenv calls strdup(), I wonder
if this is right.

grep free libc/stdlib/*env*

libc/stdlib/putenv_r.c:      (void) _free_r (reent_ptr, p);
libc/stdlib/putenv_r.c:  (void) _free_r (reent_ptr, p);

Those are error paths. Is this a leak?

--joel
Hi Joel,

There isn't an issue with putenv because you'll notice that the free of the strdup'd string is done after the call to _setenv_r (success or failure).

There is a problem because of the environ pointer. We don't know what each item points to. It may be an individually allocated string or it might not. When we add new strings and we are forced to allocate, we could keep track of those so that if these new items that are allocated get removed, then we can handle it.

-- Jeff J.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]