On Wed, Feb 24, 2016 at 10:04:40AM +0100, Harald Welte wrote:
On Wed, Feb 24, 2016 at 03:39:35AM +0100, Neels Hofmeyr wrote:
+ /* Avoid (small) mem leak: initially, vty_bind_addr is NULL. Whenever + * this gets called, it is set to a strdup. So whenever it is non-NULL, + * free it first. See also vty_get_bind_addr() for the NULL default. */ + if (vty_bind_addr) { + talloc_free((void*)vty_bind_addr); + vty_bind_addr = NULL; + }
free() on NULL is very well-defined and valid, so is talloc_free().
Really? Wasn't aware of that, indeed. Away with the ifs then. I felt the comment should explain why I treat NULL as some default string -- if I set vty_bind_addr = "127.0.0.1" then I can't free that string, thus NULL. Hmm the comment sucks, yes. Thanks! ~Neels