Do not check for null before free.

C specs says that we can safelly free a NULL pointer, so there's no reason
to check if it's null before freeing it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-05-12 14:58:15 -03:00 committed by Dirk Hohndel
parent e0c0ac5d5c
commit c86d055db7
8 changed files with 28 additions and 44 deletions

1
dive.c
View file

@ -1758,7 +1758,6 @@ static void free_events(struct event *ev)
static void free_dc(struct divecomputer *dc)
{
free(dc->sample);
if (dc->model)
free((void *)dc->model);
free_events(dc->events);
free(dc);

View file

@ -130,9 +130,8 @@ void set_default_dive_computer(const char *vendor, const char *product)
return;
if (is_default_dive_computer(vendor, product))
return;
if (default_dive_computer_vendor)
free((void *)default_dive_computer_vendor);
if (default_dive_computer_product)
free((void *)default_dive_computer_product);
default_dive_computer_vendor = strdup(vendor);
default_dive_computer_product = strdup(product);
@ -150,7 +149,7 @@ void set_default_dive_computer_device(const char *name)
return;
if (is_default_dive_computer_device(name))
return;
if (default_dive_computer_device)
free((void *)default_dive_computer_device);
default_dive_computer_device = strdup(name);
s.beginGroup("DiveComputer");

View file

@ -566,9 +566,7 @@ static void delete_trip(dive_trip_t *trip)
}
/* .. and free it */
if (trip->location)
free(trip->location);
if (trip->notes)
free(trip->notes);
free(trip);
}
@ -703,17 +701,11 @@ void delete_single_dive(int idx)
dive_table.dives[--dive_table.nr] = NULL;
/* free all allocations */
free(dive->dc.sample);
if (dive->location)
free((void *)dive->location);
if (dive->notes)
free((void *)dive->notes);
if (dive->divemaster)
free((void *)dive->divemaster);
if (dive->buddy)
free((void *)dive->buddy);
if (dive->suit)
free((void *)dive->suit);
if (dive->tag_list)
taglist_free(dive->tag_list);
free(dive);
}

View file

@ -1184,7 +1184,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
{
int o2, he, o2low;
init_decompression(dive);
if (last_pi_entry_new) /* Create the new plot data */
/* Create the new plot data */
free((void *)last_pi_entry_new);
get_dive_gas(dive, &o2, &he, &o2low);
if (he > 0) {

View file

@ -165,9 +165,7 @@ void exit_ui(void)
{
delete window;
delete application;
if (existing_filename)
free((void *)existing_filename);
if (default_dive_computer_device)
free((void *)default_dive_computer_device);
}

View file

@ -243,7 +243,7 @@ void DownloadFromDCWidget::fill_computer_list()
if (!productList["Uemis"].contains("Zurich"))
productList["Uemis"].push_back("Zurich");
descriptorLookup[QString("UemisZurich")] = (dc_descriptor_t *)mydescriptor;
descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
qSort(vendorList);
}
@ -322,7 +322,6 @@ void DownloadFromDCWidget::pickLogFile()
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer download logfile"),
filename, tr("Log files (*.log)"));
if (!logFile.isEmpty()) {
if (logfile_name)
free(logfile_name);
logfile_name = strdup(logFile.toUtf8().data());
}
@ -351,7 +350,6 @@ void DownloadFromDCWidget::pickDumpFile()
dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer binary dump file"),
filename, tr("Dump files (*.bin)"));
if (!dumpFile.isEmpty()) {
if (dumpfile_name)
free(dumpfile_name);
dumpfile_name = strdup(dumpFile.toUtf8().data());
}

View file

@ -245,10 +245,9 @@ void MainWindow::on_actionClose_triggered()
/* clear the selection and the statistics */
selected_dive = -1;
if (existing_filename) {
free((void *)existing_filename);
existing_filename = NULL;
}
cleanUpEmpty();
mark_divelist_changed(false);

View file

@ -114,11 +114,10 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
* case (one dive per year or all dives during
* one month) for yearly and monthly statistics*/
if (stats_yearly != NULL) {
free(stats_yearly);
free(stats_monthly);
free(stats_by_trip);
}
size = sizeof(stats_t) * (dive_table.nr + 1);
stats_yearly = malloc(size);
stats_monthly = malloc(size);