]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: always free buffer allocated by md_config_t::_get_val
authorJosh Durgin <josh.durgin@inktank.com>
Mon, 24 Sep 2012 22:12:11 +0000 (15:12 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 25 Sep 2012 00:57:33 +0000 (17:57 -0700)
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>
src/librados/librados.cc

index 82721a96aa5dda347fa999f9eadb3a586abf031f..274119c1b2807613989b41717b75d55e7d707bba 100644 (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;