Skip to content

Commit

Permalink
drivers/libusb1.c: nut_libusb_open(): do not keep Bus/Device/BusPort …
Browse files Browse the repository at this point in the history
…pointers to random malloc() block if we did not get a number to print there from libusb

Avoid (un-)pretty prints like:
   0.031364     [D2] - Bus: 006
   0.031366     [D2] - Bus Port: ▒UV▒▒U
   0.031368     [D2] - Device: 001

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Oct 17, 2023
1 parent 4dfbd56 commit 43552f9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
} else {
upsdebugx(1, "%s: invalid libusb bus number %i",
__func__, bus_num);
free(curDevice->Bus);
curDevice->Bus = NULL;
}

device_addr = libusb_get_device_address(device);
Expand All @@ -290,6 +292,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
} else {
upsdebugx(1, "%s: invalid libusb device address %" PRIu8,
__func__, device_addr);
free(curDevice->Device);
curDevice->Device = NULL;
}
}

Expand All @@ -305,6 +309,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
} else {
upsdebugx(1, "%s: invalid libusb bus number %i",
__func__, bus_port);
free(curDevice->BusPort);
curDevice->BusPort = NULL;
}
#endif

Expand Down

0 comments on commit 43552f9

Please sign in to comment.