Fix drive handle leak, ParseInt errors, dead code, and duplication#11
Open
wicked-wix wants to merge 1 commit into
Open
Fix drive handle leak, ParseInt errors, dead code, and duplication#11wicked-wix wants to merge 1 commit into
wicked-wix wants to merge 1 commit into
Conversation
…tion - Extract unlock() and Execute() to internal/pba to eliminate verbatim duplication across both pbainit commands - Fix defer d.Close() inside device loop (defers are function-scoped; all handles leaked until main() returned) - Fix strconv.ParseInt bitsize int8→int32 and add error handling; int8 is too small for Linux device major numbers and a malformed sysfs entry could panic on parts[1] index or silently write a wrong Mknod - Remove always-false reboot_bug variable and its dead branch (all assignments were commented out); rename pci_block→pciBlock - Replace deprecated ioutil.ReadDir/ReadFile with os.ReadDir/ReadFile Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
unlock()andExecute()were verbatim duplicates across bothpbainitcommands — moved tointernal/pba/pba.godefer d.Close()inside the block device loop is function-scoped, so all drive handles leaked untilmain()returned — replaced with explicit closes at each exit pointstrconv.ParseInt(..., 10, 8)used int8 bitsize, which is too small for Linux device major numbers; errors were silently ignored, and a missing:in sysfs output could panic onparts[1]index — now uses int32 with proper error handling and bounds checkreboot_bugwas alwaysfalse(all assignments commented out), making its branch permanently unreachable — removed variable and dead branch; renamedpci_block→pciBlockioutil.ReadDir/ReadFilewithos.ReadDir/os.ReadFile(deprecated since Go 1.16; module already requires 1.19)Test plan
go buildof all three packages compiles cleanlymakebuild produces bothelx-pba-x86_64.imgandelx-pba-interactive-x86_64.imgmake qemu-x86_64)🤖 Generated with Claude Code