Skip to content

Fix segfault from repr attempting to access attrs on uninitialized instance #520

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

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

rossbar
Copy link
Contributor

@rossbar rossbar commented Apr 2, 2024

Fixes #519

IIUC __init__ already uses handle=None as an indicator that something may have gone wrong during initialization. This PR leverages this fact to avoid calling the low-level gv.agnameof on self.handle when self.handle is None.

@aaronzo the test and proposed fix are basically ripped right out of your suggestions in #519 so I went ahead and added you as a co-author - hopefully that's okay! Should any other corner-cases be added to the test suite to ensure this fix covers the full gamut?

rossbar and others added 3 commits April 2, 2024 12:32
Segfaults on main, passes with patch.

Co-authored-by: Aaron Z <40212329+aaronzo@users.noreply.github.com>
Copy link
Contributor

@dschult dschult left a comment

Choose a reason for hiding this comment

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

Yes -- I think this is a good way to check for incomplete initialization.

Copy link
Contributor

@aaronzo aaronzo left a comment

Choose a reason for hiding this comment

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

Cheers @rossbar !

@dschult dschult merged commit 42f8ef4 into pygraphviz:main Apr 6, 2024
@jarrodmillman jarrodmillman added this to the 1.13 milestone Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

pygraphviz.AGraph.__repr__ assumes initialization was successful, can cause segmentation faults in pytest
4 participants