fix a few small memory-leaks when opening the USB device
[hmcfgusb] / flash-hmcfgusb.c
index 45d467f08451aa63d76df62fec8dc3136f9eaabb..a9ff876d75557bc8a230910cc3936e1cb83f1324 100644 (file)
@@ -93,11 +93,12 @@ int main(int argc, char **argv)
 
        if (!dev->bootloader) {
                fprintf(stderr, "\nHM-CFG-USB not in bootloader mode, entering bootloader.\n");
 
        if (!dev->bootloader) {
                fprintf(stderr, "\nHM-CFG-USB not in bootloader mode, entering bootloader.\n");
-               hmcfgusb_enter_bootloader(dev);
                fprintf(stderr, "\nWaiting for device to reappear...\n");
 
                do {
                        if (dev) {
                fprintf(stderr, "\nWaiting for device to reappear...\n");
 
                do {
                        if (dev) {
+                               if (!dev->bootloader)
+                                       hmcfgusb_enter_bootloader(dev);
                                hmcfgusb_close(dev);
                        }
                        sleep(1);
                                hmcfgusb_close(dev);
                        }
                        sleep(1);
@@ -134,7 +135,7 @@ int main(int argc, char **argv)
                        printf("Waiting for ack...\n");
                do {
                        errno = 0;
                        printf("Waiting for ack...\n");
                do {
                        errno = 0;
-                       pfd = hmcfgusb_poll(dev, 1);
+                       pfd = hmcfgusb_poll(dev, 1000);
                        if ((pfd < 0) && errno) {
                                if (errno != ETIMEDOUT) {
                                        perror("\n\nhmcfgusb_poll");
                        if ((pfd < 0) && errno) {
                                if (errno != ETIMEDOUT) {
                                        perror("\n\nhmcfgusb_poll");
@@ -165,6 +166,7 @@ int main(int argc, char **argv)
        firmware_free(fw);
 
        hmcfgusb_close(dev);
        firmware_free(fw);
 
        hmcfgusb_close(dev);
+       hmcfgusb_exit();
 
        return EXIT_SUCCESS;
 }
 
        return EXIT_SUCCESS;
 }
Impressum, Datenschutz