fix: add trap to clean up temp directory on unexpected exit#1598
Open
AnveshKolluri wants to merge 1 commit intogithub:mainfrom
Open
fix: add trap to clean up temp directory on unexpected exit#1598AnveshKolluri wants to merge 1 commit intogithub:mainfrom
AnveshKolluri wants to merge 1 commit intogithub:mainfrom
Conversation
install.sh uses \set -e\ which terminates the script on any command failure. When this happens (e.g., download 404, network error), the temp directory created by \mktemp -d\ is never cleaned up because the manual \ m -rf\ calls only cover explicitly handled error paths. Add a \ rap ... EXIT\ immediately after creating the temp directory to ensure cleanup on all exit paths. This also removes the now- redundant manual cleanup calls, simplifying the error handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents /tmp temp directory leaks in install.sh when the script exits unexpectedly (including implicit exits from set -e) by centralizing cleanup in an EXIT trap.
Changes:
- Add an
EXITtrap immediately aftermktemp -dto always remove the temp directory. - Remove now-redundant manual
rm -rf "$TMP_DIR"cleanup calls on specific error/success paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
install.shusesset -ewhich terminates the script on any command failure. When this happens (e.g., download 404, network error), the temp directory created bymktemp -dis never cleaned up — it's leaked in/tmp.The existing
rm -rf "$TMP_DIR"calls only cover manually handled error paths, butset -eimplicit exits bypass all of them.Repro:
Fix
Add
trap 'rm -rf "$TMP_DIR"' EXITimmediately aftermktemp -d. This ensures cleanup on all exit paths — normal, error, andset -eimplicit exits.The 4 redundant manual
rm -rf "$TMP_DIR"calls are removed since the trap handles them.Changes
trap 'rm -rf "$TMP_DIR"' EXITaftermktemp -drm -rf "$TMP_DIR"calls (now redundant)