Skip to content

[java] Model Deflater and Inflater as resources for Pulse resource leaks - #2275

Merged
dulmarod merged 1 commit into
meta:mainfrom
tanvir-ux:fix/pulse-deflater-inflater-leak
Oct 27, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
tanvir-ux:fix/pulse-deflater-inflater-leak

Conversation

@tanvir-ux

Copy link
Copy Markdown
Contributor

Summary

java.util.zip.Deflater and java.util.zip.Inflater hold native zlib memory that is only released by end() (or close(), since JDK 25). Their constructors were not modeled, so Pulse never reported a codec that was not ended. The existing tests FN_deflaterLeakBad and FN_inflaterLeakBad in ResourceLeaks.java show this.

  • Allocate a Java resource in the Deflater and Inflater constructors, and release it in end() and close(). These calls do not throw checked exceptions, so the release has no exceptional path.
  • Model the usual calls on a codec (setInput, finish, deflate, finished, reset, getTotalIn, ...) as no-ops. Left unknown, any of them makes Pulse stop tracking the codec.
  • Inflater.inflate may throw DataFormatException, so a missing end() on that path is reported.
  • A Deflater passed to new DeflaterOutputStream(out, deflater) is reported if it is never ended, because DeflaterOutputStream.close() only ends a deflater that it created itself.

Tests in ResourceLeaks.java: deflaterLeakBad and inflaterLeakBad (previously FN_), compressNotEndedBad, decompressNotEndedOnExceptionBad and deflaterPassedToStreamNotEndedBad, plus Ok cases for ending in a finally block, returning the codec, and ending a deflater passed to a stream.

Test plan

  • Before (main @ e5ba765, with the new tests): none of the 5 Bad cases is reported
  • After: PULSE_RESOURCE_LEAK for the 5 Bad cases; the Ok cases stay clean
  • make direct_java_pulse_test: the only issues.exp changes are the 5 new ResourceLeaks lines. (Locally I also get the unrelated lambda-name differences in InvokeDynamic/TransitiveAccess that show up on main too with my javac; not committed.)
  • ocamlformat 0.29.0 reports no changes for PulseModelsJava.ml

java.util.zip.Deflater and java.util.zip.Inflater hold native zlib memory
that is only released by end() (or close(), since JDK 25). Their
constructors were not modeled, so a codec that was never ended was not
reported; the tests for this were marked FN_.

Allocate a resource in the Deflater and Inflater constructors, and release
it in end() and close(). The usual calls on a codec (setInput, finish,
deflate, finished, ...) are modeled as no-ops so that Pulse keeps tracking
the codec through them. Inflater.inflate may throw DataFormatException, so
a missing end() on that path is reported too.
@meta-cla meta-cla Bot added the CLA Signed label Oct 27, 2026
@dulmarod
dulmarod merged commit 3467399 into meta:main Oct 27, 2026
7 checks passed
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