summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2017-07-09 14:57:41 +0200
committerPali Rohár <pali.rohar@gmail.com>2017-07-09 14:57:41 +0200
commitccec7a182f1373fb15051a1c03d28e44c4188cce (patch)
tree74410248233fe50cf469f1781a0c10c5a778fca9
parent31569c169a94640759a28acd420f27e0f39d9d3f (diff)
download0xFFFF-ccec7a182f1373fb15051a1c03d28e44c4188cce.tar.bz2
disk: Close device file handle when freeing structures
-rw-r--r--src/disk.c7
-rw-r--r--src/disk.h1
-rw-r--r--src/operations.c5
3 files changed, 12 insertions, 1 deletions
diff --git a/src/disk.c b/src/disk.c
index 486f50d..b0d4499 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -413,6 +413,13 @@ int disk_init(struct usb_device_info * dev) {
}
+void disk_exit(struct usb_device_info * dev) {
+
+ if ( dev->data >= 0 )
+ close(dev->data);
+
+}
+
enum device disk_get_device(struct usb_device_info * dev) {
return dev->device;
diff --git a/src/disk.h b/src/disk.h
index d5f367d..15eb127 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -24,6 +24,7 @@
#include "usb-device.h"
int disk_init(struct usb_device_info * dev);
+void disk_exit(struct usb_device_info * dev);
enum device disk_get_device(struct usb_device_info * dev);
diff --git a/src/operations.c b/src/operations.c
index cd7ef44..b3be2c7 100644
--- a/src/operations.c
+++ b/src/operations.c
@@ -91,8 +91,11 @@ clean:
void dev_free(struct device_info * dev) {
- if ( dev->usb )
+ if ( dev->usb ) {
+ if ( dev->usb->flash_device->protocol == FLASH_DISK )
+ disk_exit(dev->usb);
usb_close_device(dev->usb);
+ }
free(dev);
}