drivers/bus/usb: Fix potential memory leak

* Fix potential leak of 'controlData' at line 701, which is allocated
  at line 695. Pointed out by Clang Static Analyzer.
* Add NULL check to 'controlData'.

Change-Id: I96b0244d05d303b4c08ac8969f5ce5fc2e5012f9
Reviewed-on: https://review.haiku-os.org/c/1059
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2019-02-14 06:33:22 +09:00 committed by waddlesplash
parent c054900882
commit 29dcf8568b

View File

@ -693,11 +693,14 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
return B_BUFFER_OVERFLOW;
void *controlData = malloc(command.control.length);
if (controlData == NULL)
return B_NO_MEMORY;
bool inTransfer = (command.control.request_type
& USB_ENDPOINT_ADDR_DIR_IN) != 0;
if (!IS_USER_ADDRESS(command.control.data)
|| (!inTransfer && user_memcpy(controlData,
command.control.data, command.control.length) != B_OK)) {
free(controlData);
return B_BAD_ADDRESS;
}