fix(PISPI): close fd on ioctl error paths
Three ioctl calls after successful open() returned false without closing the file descriptor, leaking one fd per failed open attempt.
This commit is contained in:
@@ -106,18 +106,24 @@ bool PISPI::openDevice() {
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_MODE, &spi_mode);
|
||||
if (ret == -1) {
|
||||
piCoutObj << "can't set spi write mode";
|
||||
::close(PRIVATE->fd);
|
||||
PRIVATE->fd = -1;
|
||||
return false;
|
||||
}
|
||||
// piCoutObj << "set bits" << spi_bits;
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits);
|
||||
if (ret == -1) {
|
||||
piCoutObj << "can't set bits per word";
|
||||
::close(PRIVATE->fd);
|
||||
PRIVATE->fd = -1;
|
||||
return false;
|
||||
}
|
||||
// piCoutObj << "set speed" << spi_speed;
|
||||
ret = ioctl(PRIVATE->fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed);
|
||||
if (ret == -1) {
|
||||
piCoutObj << "can't set max write speed hz";
|
||||
::close(PRIVATE->fd);
|
||||
PRIVATE->fd = -1;
|
||||
return false;
|
||||
}
|
||||
piCoutObj << "SPI open" << path() << "speed:" << spi_speed / 1000 << "KHz"
|
||||
|
||||
Reference in New Issue
Block a user