Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix potential resource leak in AvoidStandbyModeService #3909
Replace tail recursion of the
Also tidy up
Running lsof does reveal an accumulation of file handles without this fix, although not as many as one would expect from a new stream being opened every 4 minutes - perhaps they were being closed somehow in a finaliser?
Also, JProfiler revealed an accumulation of
ripcurlx left a comment
ACK - Tested it locally on Regtest. Toggling the avoid standy by feature (I can hear the sound behaving as before) everything works as before from a user perspective. Thanks for looking into this
Replace tail recursion of the play() method with an ordinary loop, to prevent a new open JAR resource InputStream + sound file OutputStream (which were created every 4 minute playback) from accumulating on the stack, closing them inside the loop instead. (This also prevents eventual stack overflow.) Also tidy up FileUtil.resourceToFile and put the JAR URL InputStream in a try-with-resources block, to ensure that it doesn't leak either.