Skip to content

Fix drive handle leak, ParseInt errors, dead code, and duplication#11

Open
wicked-wix wants to merge 1 commit into
elastx:mainfrom
wicked-wix:main
Open

Fix drive handle leak, ParseInt errors, dead code, and duplication#11
wicked-wix wants to merge 1 commit into
elastx:mainfrom
wicked-wix:main

Conversation

@wicked-wix
Copy link
Copy Markdown

Summary

  • Extract shared code: unlock() and Execute() were verbatim duplicates across both pbainit commands — moved to internal/pba/pba.go
  • Fix resource leak: defer d.Close() inside the block device loop is function-scoped, so all drive handles leaked until main() returned — replaced with explicit closes at each exit point
  • Fix silent ParseInt bug: strconv.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 on parts[1] index — now uses int32 with proper error handling and bounds check
  • Remove dead code: reboot_bug was always false (all assignments commented out), making its branch permanently unreachable — removed variable and dead branch; renamed pci_blockpciBlock
  • Modernize: replace deprecated ioutil.ReadDir/ReadFile with os.ReadDir/os.ReadFile (deprecated since Go 1.16; module already requires 1.19)

Test plan

  • go build of all three packages compiles cleanly
  • Full make build produces both elx-pba-x86_64.img and elx-pba-interactive-x86_64.img
  • Boot test on real hardware or QEMU (make qemu-x86_64)

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant