Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions gpioioctl/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@
// The file descriptor to the Path device.
fd uintptr
// File associated with the file descriptor.
file *os.File
file *os.File
osfile *os.File
}

func (chip *GPIOChip) Name() string {
Expand Down Expand Up @@ -393,7 +394,9 @@
}
chip.file = f
chip.fd = chip.file.Fd()
os.NewFile(uintptr(chip.fd), "GPIO Chip - "+path)
// failure to maintain a reference leads to the file being garbage
// collected and the handle closed...
chip.osfile = os.NewFile(uintptr(chip.fd), "GPIO Chip - "+path)

Check warning on line 399 in gpioioctl/gpio.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/gpio.go#L397-L399

Added lines #L397 - L399 were not covered by tests
var info gpiochip_info
err = ioctl_gpiochip_info(chip.fd, &info)
if err != nil {
Expand Down Expand Up @@ -425,7 +428,10 @@
// along with any configured Lines and LineSets.
func (chip *GPIOChip) Close() {
_ = chip.file.Close()

_ = chip.osfile.Close()
chip.file = nil
chip.osfile = nil
chip.fd = 0

Check warning on line 434 in gpioioctl/gpio.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/gpio.go#L431-L434

Added lines #L431 - L434 were not covered by tests
for _, line := range chip.lines {
if line.fd != 0 {
line.Close()
Expand Down Expand Up @@ -644,7 +650,9 @@
for _, chip := range chips {
// On a pi, gpiochip0 is also symlinked to gpiochip4, checking the map
// ensures we don't duplicate the chip.
if _, found := mName[chip.Name()]; !found {
if _, found := mName[chip.Name()]; found {
chip.Close()
} else {

Check warning on line 655 in gpioioctl/gpio.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/gpio.go#L653-L655

Added lines #L653 - L655 were not covered by tests
Chips = append(Chips, chip)
mName[chip.Name()] = struct{}{}
// Now, iterate over the lines on this chip.
Expand Down