GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-151126: Check `strdup` result in readline `on_completion` by KowalskiThomas · Pull Request #156299 · python/cpython

Conversation

@KowalskiThomas

@KowalskiThomas KowalskiThomas commented Aug 23, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Relates to #151126.

  • Issue: Many places have missing PyErr_NoMemory() call after failing memory allocation #151126

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KowalskiThomas
pythongh-151126: Check strdup result in readline on_completion
7c08f01
Add a NULL check and an explicit PyErr_NoMemory() before goto
error.
@bedevere-app bedevere-app Bot mentioned this pull request Aug 23, 2026
Many places have missing PyErr_NoMemory() call after failing memory allocation #151126
Open
@KowalskiThomas
KowalskiThomas marked this pull request as ready for review September 1, 2026 13:29
@bedevere-app bedevere-app Bot added the awaiting review label Sep 1, 2026
cmaloney
cmaloney reviewed Oct 21, 2026
View reviewed changes
Comment thread Modules/readline.c
@@ -1272,6 +1272,10 @@ on_completion(const char *text, int state)
goto error;
result = strdup(PyBytes_AS_STRING(encoded));

@cmaloney cmaloney Oct 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@KowalskiThomas KowalskiThomas Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cmaloney
cmaloney reviewed Oct 21, 2026
View reviewed changes
Comment thread Modules/readline.c
result = strdup(PyBytes_AS_STRING(encoded));
Py_DECREF(encoded);
if (result == NULL) {
PyErr_NoMemory();

@cmaloney cmaloney Oct 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@KowalskiThomas KowalskiThomas Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

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...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KowalskiThomas

KowalskiThomas commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Seems like this really is an unlikely edge case and there's no straightforward fix to it (see this comment) so I will just close the PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KowalskiThomas KowalskiThomas closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cmaloney cmaloney cmaloney left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@KowalskiThomas @cmaloney
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.