Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop dereferencing end() iterators #1748

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

greglandrum
Copy link
Member

The new code for doing range-based loops over atoms and bonds illegally dereferences the end() vertex/edge iterators when CXX{Atom,Bond}Iterator::end() is called. This fixes that.

There's also a memory leak fix for one of the recently added tests.

@greglandrum greglandrum added this to the 2018_03_1 milestone Feb 14, 2018

Edge &operator*() { return current; }
Edge &operator*() {
current = (*graph)[*pos];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we don't need current anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought initially, but you need it in order to be able to use references in the range for loops - for(auto &at: mol.atoms()).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! I'm doing some sanity checks here just trying to figure out when the end was being dereferences as I didn't catch it initially with valgrind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valgrind only showed it for me when I built in debug mode. I noticed it first in a debug build on windows, where the dereference led directly to a crash.
The problem itself was happening here:
https://github.com/rdkit/rdkit/blob/modern_cxx/Code/GraphMol/ROMol.h#L115
when this call is made:
https://github.com/rdkit/rdkit/blob/modern_cxx/Code/GraphMol/ROMol.h#L131

@greglandrum greglandrum merged commit 0c53063 into rdkit:modern_cxx Feb 22, 2018
@greglandrum greglandrum deleted the fix/dereferencing_end_iters branch February 22, 2018 02:43
ricrogz pushed a commit to ricrogz/rdkit that referenced this pull request Aug 21, 2018
* cleanup the build requirements for test-valgrind

* cleanup a recently added test

* the new iterators would dereference end() iterators. Fix that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants