librados: always free buffer allocated by md_config_t::_get_val

CID 717083: Resource leak (RESOURCE_LEAK)
At (3): Variable "str" going out of scope leaks the storage it points
to.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
This commit is contained in:
Josh Durgin 2012-09-24 15:12:11 -07:00
parent a677f47926
commit 4567a6df2f

View File

@ -1113,11 +1113,13 @@ int librados::Rados::conf_set(const char *option, const char *value)
int librados::Rados::conf_get(const char *option, std::string &val)
{
char *str;
char *str = NULL;
md_config_t *conf = client->cct->_conf;
int ret = conf->get_val(option, &str, -1);
if (ret)
if (ret) {
free(str);
return ret;
}
val = str;
free(str);
return 0;