From 8db2c6a9693d2385dd725a1519b2278b0229983f Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Sat, 19 Dec 2015 20:27:31 -0500 Subject: [PATCH] librgw: fix initialization of string_ref from temporary Found by valgrind. The good news: amounts to proof that the sref notation works. Signed-off-by: Matt Benjamin --- src/common/cohort_lru.h | 1 + src/rgw/rgw_file.h | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/common/cohort_lru.h b/src/common/cohort_lru.h index 2f83b4230556f..0baa3a25fc883 100644 --- a/src/common/cohort_lru.h +++ b/src/common/cohort_lru.h @@ -324,6 +324,7 @@ namespace cohort { if (csz) { p.csz = csz; p.cache = (T**) ::operator new(csz * sizeof(T*)); + memset(p.cache, 0, csz * sizeof(T*)); } locks.push_back(&p.lock); } diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 35eaa9f0acc51..2c902306273d9 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -526,7 +526,8 @@ namespace rgw { cct->_conf->rgw_nfs_fhcache_size), fh_lru(cct->_conf->rgw_nfs_lru_lanes, cct->_conf->rgw_nfs_lru_lane_hiwat), - uid(_uid), key(_user_id, _key) { + uid(_uid), key(_user_id, _key), + flags(0) { /* no bucket may be named rgw_fs_inst-(.*) */ fsid = RGWFileHandle::root_name + "rgw_fs_inst-" + @@ -565,6 +566,9 @@ namespace rgw { return fhr; RGWFileHandle::FHCache::Latch lat; + memset(&lat, 0, sizeof(lat)); // XXXX testing + + std::string obj_name{name}; std::string key_name{parent->make_key_name(name)}; @@ -857,9 +861,10 @@ public: return 0; } - int operator()(const boost::string_ref& name, - const boost::string_ref& marker) { + int operator()(const boost::string_ref name, + const boost::string_ref marker) { /* hash offset of name in parent (short name) for NFS readdir cookie */ + std::string sname{name}; uint64_t off = XXH64(name.data(), name.length(), fh_key::seed); *offset = off; /* update traversal cache */ @@ -877,15 +882,15 @@ public: struct req_state* s = get_state(); for (const auto& iter : objs) { + boost::string_ref sref {iter.key.name}; + std::cout << "readdir objects prefix: " << prefix - << " obj: " << iter.key.name << std::endl; + << " obj: " << sref << std::endl; - size_t last_del = iter.key.name.find_last_of('/'); - boost::string_ref sref; + size_t last_del = sref.find_last_of('/'); if (last_del != string::npos) - sref = boost::string_ref{iter.key.name.substr(last_del+1)}; - else - sref = boost::string_ref{iter.key.name}; + sref = sref.substr(last_del+1); + /* if we find a trailing slash in a -listing- the parent is an * empty directory */ @@ -914,12 +919,11 @@ public: if (iter.first.back() == '/') const_cast(iter.first).pop_back(); - size_t last_del = iter.first.find_last_of('/'); - boost::string_ref sref; + boost::string_ref sref{iter.first}; + + size_t last_del = sref.find_last_of('/'); if (last_del != string::npos) - sref = boost::string_ref{iter.first.substr(last_del+1)}; - else - sref = boost::string_ref{iter.first}; + sref = sref.substr(last_del+1); lsubdout(cct, rgw, 15) << "RGWReaddirRequest " << __func__ << " " -- 2.39.5