fixup AsWritePvt to be non-copyable

Avoids double free via asTrapWriteAfterWrite() with c++98
This commit is contained in:
Michael Davidsaver
2022-06-21 08:48:17 -07:00
parent 69a7bb3795
commit cb1b41c1b2
2 changed files with 20 additions and 12 deletions

View File

@ -74,13 +74,20 @@ struct QSRV_API PDBProvider : public epics::pvAccess::ChannelProvider,
QSRV_API
void QSRVRegistrar_counters();
class QSRV_API AsWritePvt {
class AsWritePvt {
void * pvt;
public:
AsWritePvt() :pvt(NULL) {}
explicit AsWritePvt(void * pvt): pvt(pvt) {}
~AsWritePvt() {
asTrapWriteAfterWrite(pvt);
}
void swap(AsWritePvt& o) {
std::swap(pvt, o.pvt);
}
private:
AsWritePvt(const AsWritePvt&);
AsWritePvt& operator=(const AsWritePvt&);
};
#endif // PDB_H

View File

@ -350,22 +350,23 @@ void PDBGroupPut::put(pvd::PVStructure::shared_pointer const & value,
// assume value may be a different struct each time... lot of wasted prep work
const size_t npvs = channel->pv->members.size();
std::vector<std::tr1::shared_ptr<PVIF> > putpvif(npvs);
std::vector<AsWritePvt> asWritePvt;
pvd::shared_vector<AsWritePvt> asWritePvt(npvs);
for(size_t i=0; i<npvs; i++)
{
PDBGroupPV::Info& info = channel->pv->members[i];
asWritePvt.push_back(AsWritePvt(
asTrapWriteWithData(channel->aspvt.at(i).aspvt,
std::string(channel->cred.user.begin(), channel->cred.user.end()).c_str(),
std::string(channel->cred.host.begin(), channel->cred.host.end()).c_str(),
info.chan,
AsWritePvt wrt(asTrapWriteWithData(
channel->aspvt.at(i).aspvt,
&channel->cred.user[0],
&channel->cred.host[0],
info.chan.chan,
info.chan->final_type,
info.chan->final_no_elements,
NULL
)
));
);
asWritePvt[i].swap(wrt);
if(!info.allowProc) continue;
putpvif[i].reset(info.builder->attach(value, info.attachment));