Add ftdi_eeprom_free() to free allocated memory in eeprom
[libftdi] / src / ftdi.c
index 6db70f1..4d10b73 100644 (file)
@@ -163,7 +163,7 @@ struct ftdi_context *ftdi_new(void)
 */
 int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface)
 {
-    if (ftdi == NULL || ftdi->usb_dev == NULL)
+    if (ftdi == NULL)
         ftdi_error_return(-2, "USB device unavailable");
 
     switch (interface)
@@ -497,7 +497,7 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev)
             }
             else
             {
-                ftdi_error_return(-3, "unable to set usb configuration. Make sure ftdi_sio is unloaded!");
+                ftdi_error_return(-3, "unable to set usb configuration. Make sure the default FTDI driver is not in use");
             }
         }
     }
@@ -512,7 +512,7 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev)
         }
         else
         {
-            ftdi_error_return(-5, "unable to claim usb device. Make sure ftdi_sio is unloaded!");
+            ftdi_error_return(-5, "unable to claim usb device. Make sure the default FTDI driver is not in use");
         }
     }
 
@@ -2132,6 +2132,27 @@ void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom)
 }
 
 /**
+    Frees allocated memory in eeprom.
+
+    \param eeprom Pointer to ftdi_eeprom
+*/
+void ftdi_eeprom_free(struct ftdi_eeprom *eeprom)
+{
+    if (eeprom->manufacturer != 0) {
+        free(eeprom->manufacturer);
+        eeprom->manufacturer = 0;
+    }
+    if (eeprom->product != 0) {
+        free(eeprom->product);
+        eeprom->product = 0;
+    }
+    if (eeprom->serial != 0) {
+        free(eeprom->serial);
+        eeprom->serial = 0;
+    }
+}
+
+/**
     Build binary output from ftdi_eeprom structure.
     Output is suitable for ftdi_write_eeprom().