Metadata memory deallocation on share failure
//File src/data_descriptor.cxx line 138
void Data_descriptor::share(void* data, bool read, bool write)
{
share(Ref {data, &free, m_type->evaluate(m_context), read, write}, false, false);
}
void* Data_descriptor::share(Ref data_ref, bool read, bool write)
{
// metadata must provide read access
if (metadata() && !Ref_r(data_ref)) {
throw Error{PDI_ERR_RIGHT, "Metadata sharing must offer read access"};
}
...
}
On sharing metadata without read privilege (e.g. PDI_expose("dsize", dsize, PDI_NONE);
) memory under void* data
is automatically freed (because we create new Ref and destroy it without chance to reclaim the pointer). This results in double memory free when it's on heap or undefined behavior when it's on stack.