Jason Biggs


On Thu, Dec 29, 2022 at 3:22 PM Jarod Younker <jarod_youn...@hotmail.com>
wrote:

> The code compiles fine, but I’m running into a memory deallocation issue
> in ‘Dummy’ if I use ROMol derived from pickled strings:
>
>
>
> Error: free(): double free detected in tcache 2
>
>
>
> If, however, I go from pickle to SMILES and then to ROMol there is no
> memory error.  Somewhere, I’m deallocating memory twice.  Any help would be
> appreciated.
>
>
>
> std::string MolPickle2Smiles(std::string& pickle) {
>
>
>
>   RDKit::ROMol molecule;
>
>   RDKit::MolPickler::molFromPickle(pickle,molecule);
>
>   return RDKit::MolToSmiles(molecule);
>
>
>
> }
>
>
>
> bool Dummy(std::string& pickle1, std::string& pickle2) {
>
>
>
>   RDKit::MOL_SPTR_VECT reacts;
>
>   reacts.clear();
>
>
>
>   //THIS DOESN’T WORK
>
>   RDKit::ROMol molecule;
>

By declaring the 'molecule' in that way you ensure that it will be deleted
automatically when the function exits.  To create an ROMol that persists
after the Dummy function exits you need the 'new' keyword.  Even better is
to start with a smart pointer out of the gate:

bool Dummy(std::string& pickle1) {
  RDKit::MOL_SPTR_VECT reacts;
  reacts.clear();
  RDKit::ROMOL_SPTR mptr;
  RDKit::MolPickler::molFromPickle(pickle1, mptr.get());
  reacts.push_back(mptr);
  return 0;
}

Hope that helps
Jason


>   RDKit::MolPickler::molFromPickle(pickle1,molecule);
>
>   reacts.push_back(RDKit::ROMOL_SPTR(&molecule));
>
>
>
>   //THIS WORKS
>
>
> //reacts.push_back(RDKit::ROMOL_SPTR(RDKit::SmilesToMol(MolPickle2Smiles(pickle1))));
>
>
>
>   return 0;
>
>
>
> }
>
> Sent from my iPhone
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to