sr_scpi_hw_info_free(): Allow NULL as argument.

This commit is contained in:
Uwe Hermann 2017-03-08 19:45:23 +01:00
parent ce375f2a39
commit 7b365c4719
4 changed files with 13 additions and 16 deletions

View File

@ -98,8 +98,7 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi
return sdi;
fail:
if (hw_info)
sr_scpi_hw_info_free(hw_info);
sr_scpi_hw_info_free(hw_info);
sr_dev_inst_free(sdi);
g_free(devc);

View File

@ -144,8 +144,7 @@ static struct sr_dev_inst *rs_probe_serial_device(struct sr_scpi_dev_inst *scpi)
return sdi;
fail:
if (hw_info)
sr_scpi_hw_info_free(hw_info);
sr_scpi_hw_info_free(hw_info);
sr_dev_inst_free(sdi);
g_free(devc);
return NULL;

View File

@ -109,8 +109,7 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
return sdi;
fail:
if (hw_info)
sr_scpi_hw_info_free(hw_info);
sr_scpi_hw_info_free(hw_info);
sr_dev_inst_free(sdi);
g_free(devc);

View File

@ -934,17 +934,17 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
/**
* Free a sr_scpi_hw_info struct.
*
* @param hw_info Pointer to the struct to free.
*
* This function is safe to call with a NULL pointer.
* @param hw_info Pointer to the struct to free. If NULL, this
* function does nothing.
*/
SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info)
{
if (hw_info) {
g_free(hw_info->manufacturer);
g_free(hw_info->model);
g_free(hw_info->serial_number);
g_free(hw_info->firmware_version);
g_free(hw_info);
}
if (!hw_info)
return;
g_free(hw_info->manufacturer);
g_free(hw_info->model);
g_free(hw_info->serial_number);
g_free(hw_info->firmware_version);
g_free(hw_info);
}