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

Decref filepath only if the filename is not needed anymore #114

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

frenzymadness
Copy link
Contributor

Filename is created by:

char *filename = PyBytes_AS_STRING(filepath);

which means that filename contains only a pointer to the string in filepath and if the filepath is destroyed before we check the status, the filename cannot be used in the error message.

I have no idea why this happens to us only on i686 architecture with Python 3.12 but this change fixes the problem. Without it, the tests test_nondatabase fail with non-matching regex for the expected error message:

AssertionError: "Error opening database file \(README.rst\). Is this a valid MaxMind DB file\?" does not match "Error opening database file (dEADdEADdE). Is this a valid MaxMind DB file?"

@@ -111,6 +110,8 @@ static int Reader_init(PyObject *self, PyObject *args, PyObject *kwds) {
return -1;
}

Py_XDECREF(filepath);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! This makes sense, but I think we would leak above when there is an error opening the file. I think we would want a similar Py_XDECREF(filepath); before the return there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right. Thanks for the superquick review. Should be fixed by the second decref now.

Copy link
Member

@oschwald oschwald left a comment

Choose a reason for hiding this comment

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

Thank you!

@oschwald oschwald merged commit 5583c5b into maxmind:main Jun 28, 2023
@oschwald
Copy link
Member

I released 2.4.0 with this change.

@frenzymadness frenzymadness deleted the fix_32bit branch June 28, 2023 17:31
@frenzymadness
Copy link
Contributor Author

Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants