Coverity reports a leaked storage variable.
I do believe just set spec to NULL will cover this issue.
This approach was suggested by kevlo@.
I have sent another patch that is pretty much wrong.
Differential D981
Coverity CID 1248848 - Leaked Storage Variable. araujo on Oct 21 2014, 6:08 AM. Authored by Tags None Referenced Files
Subscribers
Details
Diff Detail
Event TimelineComment Actions As replied to araujo before I created my account: I think the change is wrong. spec doesn't point to the beginning of the string after the first iteration. So you can't free spec anymore. In order to properly free the string with freeenv, we need to save the pointer returned from getenv. Also: we probably want to free the string in the normal case as well as the error case. You just fixed the error case. Comment Actions Yes, you are right, at line 276 it will iterate and can't be freeenv anymore, but it can be set to NULL before the return.
I'm gonna make another patch. Comment Actions Setting spec to NULL does nothing. The compiler will effectively remove it as being dead-code. Also: the CID is about a memory leak. The leak is caused by kern_getenv() doing a strdup() in certain conditions and in order to free the memory allocated by strdup(), one must call kern_freeenv(). Setting spec to NULL does not fix the problem of not calling kern_freeenv() Comment Actions Marcelo, I sent marcel@ the diff for review yesterday and he's ok with it. Comment Actions Committed: https://svnweb.freebsd.org/base?view=revision&revision=273576 Thank you guys. |