Skip to content

fix(ImageInput): guarantee close()-on-failure for all open() methods - #5398

Merged
lgritz merged 2 commits into
AcademySoftwareFoundation:mainfrom
lgritz:lg-openfailclose
Aug 15, 2026
Merged

fix(ImageInput): guarantee close()-on-failure for all open() methods#5398
lgritz merged 2 commits into
AcademySoftwareFoundation:mainfrom
lgritz:lg-openfailclose

Conversation

@lgritz

@lgritz lgritz commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

If ImageInput::open() encounters an error and returns false, is the object expected to be left in the same state as a newly constructed, never-opened instance (other than having an error that can be retrieved), as if close() had been called? Or is it up to the caller to do the close()? We were never quite clear on this, and some plugins have any open() failures do a close() before returning, but others did not.

Clean this up once and for all by documenting ImageInput::open() to make clear that the contract is that a failed open() will close the file and needs no further cleanup action on the part of the caller.

Audit all readers and ensure that in every instance that an open() method returns false to indicate an error, close() is also called.

Note that:

  • The error message is stil retrievable from the closed ImageInput.
  • If an IOProxy was passed to the ImageInput to use, that proxy is still open and able to be used for further reads to the same file.

Assisted-by: Claude Code / Claude Sonnet 5
Co-authored by: Brecht Van Lommel brecht@blender.org

@brechtvl brechtvl left a comment

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.

The changes look good to me, but they appear to be incomplete.

Here's a patch made with Claude assistance to find more missing cases. It includes some drive-by fixes and simplifications that seemed relevant to include.
missed_close_and_other_fixes.patch

lgritz added 2 commits August 14, 2026 17:03
If ImageInput::open() encounters an error and returns false, is the
object expected to be left in the same state as a newly constructed,
never-opened instance (other than having an error that can be
retrieved), as if close() had been called? Or is it up to the caller
to do the close()?  We were never quite clear on this, and some
plugins have any open() failures do a close() before returning, but
others did not.

Clean this up once and for all by documenting ImageInput::open() to
make clear that the contract is that a failed open() will close the
file and needs no further cleanup action on the part of the caller.

Audit all readers and ensure that in every instance that an open()
method returns false to indicate an error, close() is also called.

Note that:
- The error message is stil retrievable from the closed ImageInput.
- If an IOProxy was passed to the ImageInput to use, that proxy is
  still open and able to be used for further reads to the same file.

Assisted-by: Claude Code / Claude Sonnet 5

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Co-authored by: Brecht Van Lommel <brecht@blender.org>
Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz

lgritz commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Amended with your changes, thanks @brechtvl !

@lgritz
lgritz merged commit 19fb2d7 into AcademySoftwareFoundation:main Aug 15, 2026
30 checks passed
@lgritz
lgritz deleted the lg-openfailclose branch August 15, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants