Skip to content

[java] Model Pipe.open for Pulse resource leaks - #2343

Open
tanvir-ux wants to merge 1 commit into
meta:mainfrom
tanvir-ux:fix/pipe-resource-leak
Open

tanvir-ux wants to merge 1 commit into
meta:mainfrom
tanvir-ux:fix/pipe-resource-leak

Conversation

@tanvir-ux

Copy link
Copy Markdown
Contributor

Pipe.open returns a pipe whose source and sink channels each own a native file descriptor until close. Pipe itself is not Closeable, so Pulse never allocated those channels and not closing them was missed. source and sink return the channels allocated by open. read and write may throw IOException without closing the channel.

make -C infer/tests/codetoanalyze/java/pulse test

Please see CONTRIBUTING.md for how to set up your development environment and run tests.

Pipe.open returns a pipe whose source and sink channels each own a
native file descriptor until close. Pipe itself is not Closeable, so
Pulse never allocated those channels and not closing them was missed.
source and sink return the channels allocated by open. read and write
may throw IOException without closing the channel.

make -C infer/tests/codetoanalyze/java/pulse test
@meta-cla meta-cla Bot added the CLA Signed label Dec 1, 2026
@dulmarod

dulmarod commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

I need more details about the model, how the objects look like, etc.

@tanvir-ux

Copy link
Copy Markdown
Contributor Author

Hi Dulma,

Pipe.open() creates three objects:

  1. A Pipe.SourceChannel, tracked as a Java resource. It owns the readable native file descriptor until close().
  2. A Pipe.SinkChannel, also tracked as a Java resource. It owns the writable native file descriptor until close().
  3. The Pipe itself, allocated with alloc_no_leak_not_null. Pipe is not Closeable, so it is not the resource. It only holds the two channels.

The channels are stored on the Pipe under the model fields __infer_pipe_source and __infer_pipe_sink. source() and sink() load those same values, so closing pipe.source() closes the channel that open() allocated, and a later source() call returns that same channel.

SourceChannel.read and SinkChannel.write are modeled as uses that may throw IOException and do not close the channel. Without that, Pulse treated them as unknown and dropped the channel.

This is the same gap as Selector.open in #2337: open() does not go through a modeled constructor, and Pipe itself is not Closeable.

Thanks,
Tanvir

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants