cmd: Avoid premature OptionAsString free
authorAndrew Deason <adeason@sinenomine.net>
Thu, 24 May 2012 19:53:59 +0000 (14:53 -0500)
committerDerrick Brashear <shadow@dementix.org>
Wed, 27 Jun 2012 12:33:58 +0000 (05:33 -0700)
commite1ff7148cce62f7c34614dc1ac1edc909dea1c55
tree2890d59116e0c7da0898b7034bdad3d46a3c5dde
parent1fbe83f9aacfc36a9c426ba1fd18ad7c72869dc1
cmd: Avoid premature OptionAsString free

Only free the previously-set string value if we're actually going to
change it. This avoids the scenario where a caller does something
like:

  char *str = strdup("defaultval");
  /* ... */
  cmd_OptionAsString(as, OPT_foo, &str);

resulting in 'str' pointing to freed memory when the relevant option
is not specified, or there is some other error.

Change-Id: If1f94d5eb39cc4dba9a4195ff20850ff81737eb9
Reviewed-on: http://gerrit.openafs.org/7475
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
src/cmd/cmd.c