Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise :exc:`MemoryError` on allocation failure in the :mod:`!readline`
completion callback.
4 changes: 4 additions & 0 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,10 @@ on_completion(const char *text, int state)
goto error;
result = strdup(PyBytes_AS_STRING(encoded));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should actually change to _PyMem_Strdup while we're here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do depending on whether we just close the PR or not!

Py_DECREF(encoded);
if (result == NULL) {
PyErr_NoMemory();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this works right as the goto err will clear the memory error set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤔 You're right, indeed.

Looking a bit more at it, I'm starting to wonder if the lack of checking strdup result is an oversight or on purpose, since the function ignores all errors that can happen and doesn't seem to ever return / raise them.

So I'm not quite sure what I should do here. It seems like actually bubbling the exception all the way up to input would require "setting the exception" somewhere, so that the actual "reading loop" can detect it and abort/actually raise the exception.

Alternatively, it might make sense to just explicitly ignore the result of strdup (since at this point it's likely the user impact is none or near none), and if strdup it's also likely things will blow up not much later...

goto error;
}
}
Py_DECREF(r);
goto done;
Expand Down
Loading