From: Antonio Ospite Date: Fri, 30 Sep 2011 11:59:17 +0000 (+0200) Subject: kinect_upload_fw: fix issues shown by valgrind --leak-check=full --show-reachable=yes X-Git-Tag: v0.1~6 X-Git-Url: https://git.ao2.it/kinect-audio-setup.git/commitdiff_plain/33509a9b17731672efb1215487538dfedb18ddce?ds=sidebyside;hp=19bf8b8b7bdf5db13a5506eafabe1aec15a65aaa kinect_upload_fw: fix issues shown by valgrind --leak-check=full --show-reachable=yes Fix a "possibly lost" issue due to a missing call to libusb_exit() when exiting after libusb_open_device_with_vid_pid() fails. Fix a "still reachable" issue due to a missing fclose(). --- diff --git a/kinect_upload_fw/kinect_upload_fw.c b/kinect_upload_fw/kinect_upload_fw.c index 80d435f..5cf1abb 100644 --- a/kinect_upload_fw/kinect_upload_fw.c +++ b/kinect_upload_fw/kinect_upload_fw.c @@ -124,6 +124,7 @@ static int get_reply(void) { int main(int argc, char** argv) { char default_filename[] = "firmware.bin"; char* filename = default_filename; + int res = 0; if (argc == 2) { filename = argv[1]; @@ -141,7 +142,8 @@ int main(int argc, char** argv) { dev = libusb_open_device_with_vid_pid(NULL, 0x045e, 0x02ad); if (dev == NULL) { fprintf(stderr, "Couldn't open device.\n"); - return 1; + res = -ENODEV; + goto fail_libusb_open; } libusb_set_configuration(dev, 1); @@ -160,7 +162,6 @@ int main(int argc, char** argv) { LOG("About to send: "); dump_bl_cmd(cmd); - int res; int transferred; res = libusb_bulk_transfer(dev, 1, (unsigned char*)&cmd, sizeof(cmd), &transferred, 0); @@ -225,6 +226,8 @@ int main(int argc, char** argv) { cleanup: libusb_close(dev); +fail_libusb_open: libusb_exit(NULL); - return 0; + fclose(fw); + return res; }