From 4567a6df2f45e947be0eb248529f7610ecc2305c Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 24 Sep 2012 15:12:11 -0700 Subject: [PATCH] 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 --- src/librados/librados.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 82721a96aa5..274119c1b28 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -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;