Commit 96fc04cb4f21290025f7e634911ecd2c20a7b61c
1 parent
20a3c873
Fix memory leak.
Showing
2 changed files
with
4 additions
and
2 deletions
Makefile
main.c
| ... | ... | @@ -127,7 +127,7 @@ int Initialize_Device(libusb_context ** ctx, libusb_device_handle ** usb_device) |
| 127 | 127 | |
| 128 | 128 | int ep_write(void *buf, int len, libusb_device_handle * usb_device) |
| 129 | 129 | { |
| 130 | - int a_len; | |
| 130 | + int a_len = 0; | |
| 131 | 131 | int ret = |
| 132 | 132 | libusb_control_transfer(usb_device, LIBUSB_REQUEST_TYPE_VENDOR, 0, |
| 133 | 133 | len & 0xffff, len >> 16, NULL, 0, 1000); |
| ... | ... | @@ -362,11 +362,13 @@ int file_server(libusb_device_handle * usb_device) |
| 362 | 362 | if(read != file_size) |
| 363 | 363 | { |
| 364 | 364 | printf("Failed to read from input file\n"); |
| 365 | + free(buf); | |
| 365 | 366 | return -1; |
| 366 | 367 | } |
| 367 | 368 | |
| 368 | 369 | int sz = ep_write(buf, file_size, usb_device); |
| 369 | 370 | |
| 371 | + free(buf); | |
| 370 | 372 | fclose(fp); |
| 371 | 373 | fp = NULL; |
| 372 | 374 | ... | ... |