The Python code calls directly into the c++ code. The code in
reestablish_backing() adjusts and updates the pointers accordingly:
https://github.com/rescrv/HyperDex/blob/master/common/hyperspace.cc#L170-L186
After the call to reestablish_backing, the s.sc.attrs will equal
m_attrs, not the attrs vector on the stack.
If your patch fixes the issue, it points to a problem in
reestablish_backing, which makes sure all pointers point to internal
storage by copying/rewriting/etc. The problem should be fixed in that
function; otherwise, it could occur elsewhere and the patch is only a
fix for this particular crash and it might introduce a memory leak.
From your debugging, did you see the pointer to s.sc.attrs point to
the stack even at the return point from the function?
-Robert
> From 31d22cc7f6f7d09a18dfe41395308fbe6248fa43 Mon Sep 17 00:00:00 2001
> From: cnangel <
junli...@alibaba-inc.com>
> Date: Wed, 3 Feb 2016 17:23:42 +0800
> Subject: [PATCH] patch space name
> MIME-Version: 1.0
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: 8bit
>
> ---
> common/hyperspace.cc | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/common/hyperspace.cc b/common/hyperspace.cc
> index 0c2e1a8..2146393 100644
> --- a/common/hyperspace.cc
> +++ b/common/hyperspace.cc
> @@ -226,23 +226,25 @@ e::unpacker
> hyperdex :: operator >> (e::unpacker up, space& s)
> {
> e::slice name;
> - std::vector<std::string> strs;
> - std::vector<attribute> attrs;
> + std::auto_ptr<std::vector<std::string> > strs(new std::vector<std::string>);
> + e::array_ptr<attribute> attrs;
> uint16_t num_subspaces;
> uint16_t num_indices;
> up = up >>
s.id >> name >> s.fault_tolerance >> s.sc.attrs_sz
> >> num_subspaces >> num_indices;
> - strs.push_back(std::string(name.cdata(), name.size()));
> -
s.name = strs.back().c_str();
> + strs->push_back(std::string(name.cdata(), name.size()));
> +
s.name = strs->back().c_str();
>
> // Unpack all attributes
> + attrs = new attribute[s.sc.attrs_sz];
> for (size_t i = 0; !up.error() && i < s.sc.attrs_sz; ++i)
> {
> e::slice attr;
> hyperdatatype type;
> up = up >> attr >> type;
> - strs.push_back(std::string(attr.cdata(), attr.size()));
> - attrs.push_back(attribute(strs.back().c_str(), type));
> + strs->push_back(std::string(attr.cdata(), attr.size()));
> + attrs[i].name = strs->back().c_str();
> + attrs[i].type = type;
>
> if (type == HYPERDATATYPE_MACAROON_SECRET)
> {
> @@ -250,8 +252,7 @@ hyperdex :: operator >> (e::unpacker up, space& s)
> }
> }
>
> - s.sc.attrs = &attrs.front();
> - s.sc.attrs_sz = attrs.size();
> + s.sc.attrs = attrs.get();
>
> // Unpack subspaces
> s.subspaces.resize(num_subspaces);
> --
> 2.5.0
>