Repository navigation
[java] Model Deflater and Inflater as resources for Pulse resource leaks - #2275
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
java.util.zip.Deflaterandjava.util.zip.Inflaterhold native zlib memory that is only released byend()(orclose(), since JDK 25). Their constructors were not modeled, so Pulse never reported a codec that was not ended. The existing testsFN_deflaterLeakBadandFN_inflaterLeakBadinResourceLeaks.javashow this.DeflaterandInflaterconstructors, and release it inend()andclose(). These calls do not throw checked exceptions, so the release has no exceptional path.setInput,finish,deflate,finished,reset,getTotalIn, ...) as no-ops. Left unknown, any of them makes Pulse stop tracking the codec.Inflater.inflatemay throwDataFormatException, so a missingend()on that path is reported.Deflaterpassed tonew DeflaterOutputStream(out, deflater)is reported if it is never ended, becauseDeflaterOutputStream.close()only ends a deflater that it created itself.Tests in
ResourceLeaks.java:deflaterLeakBadandinflaterLeakBad(previouslyFN_),compressNotEndedBad,decompressNotEndedOnExceptionBadanddeflaterPassedToStreamNotEndedBad, plusOkcases for ending in afinallyblock, returning the codec, and ending a deflater passed to a stream.Test plan
Badcases is reportedPULSE_RESOURCE_LEAKfor the 5Badcases; theOkcases stay cleanmake direct_java_pulse_test: the onlyissues.expchanges are the 5 newResourceLeakslines. (Locally I also get the unrelated lambda-name differences in InvokeDynamic/TransitiveAccess that show up on main too with my javac; not committed.)ocamlformat0.29.0 reports no changes forPulseModelsJava.ml