diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-05-12 14:58:15 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-13 09:26:50 +0900 |
commit | c86d055db77cdeef6049449ac79fe404c40d28cc (patch) | |
tree | f0e53f8d42567a670567e7600de287dcdde5b627 | |
parent | e0c0ac5d5c7c218011278fbe57da291a7e10c8eb (diff) | |
download | subsurface-c86d055db77cdeef6049449ac79fe404c40d28cc.tar.gz |
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>
-rw-r--r-- | dive.c | 3 | ||||
-rw-r--r-- | divecomputer.cpp | 11 | ||||
-rw-r--r-- | divelist.c | 24 | ||||
-rw-r--r-- | profile.c | 4 | ||||
-rw-r--r-- | qt-gui.cpp | 6 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 8 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 7 | ||||
-rw-r--r-- | statistics.c | 9 |
8 files changed, 28 insertions, 44 deletions
@@ -1758,8 +1758,7 @@ 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((void *)dc->model); free_events(dc->events); free(dc); } diff --git a/divecomputer.cpp b/divecomputer.cpp index c02bbea55..6044f1aa6 100644 --- a/divecomputer.cpp +++ b/divecomputer.cpp @@ -130,10 +130,9 @@ 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); + + free((void *)default_dive_computer_vendor); + free((void *)default_dive_computer_product); default_dive_computer_vendor = strdup(vendor); default_dive_computer_product = strdup(product); s.beginGroup("DiveComputer"); @@ -150,8 +149,8 @@ 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); + + free((void *)default_dive_computer_device); default_dive_computer_device = strdup(name); s.beginGroup("DiveComputer"); s.setValue("dive_computer_device", name); diff --git a/divelist.c b/divelist.c index f8d3d70d3..b19971087 100644 --- a/divelist.c +++ b/divelist.c @@ -566,10 +566,8 @@ 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->location); + free(trip->notes); free(trip); } @@ -703,18 +701,12 @@ 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((void *)dive->location); + free((void *)dive->notes); + free((void *)dive->divemaster); + free((void *)dive->buddy); + free((void *)dive->suit); + taglist_free(dive->tag_list); free(dive); } @@ -1184,8 +1184,8 @@ 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 */ - free((void *)last_pi_entry_new); + /* Create the new plot data */ + free((void *)last_pi_entry_new); get_dive_gas(dive, &o2, &he, &o2low); if (he > 0) { pi->dive_type = TRIMIX; diff --git a/qt-gui.cpp b/qt-gui.cpp index 868389eab..9d6dde45f 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -165,10 +165,8 @@ 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); + free((void *)existing_filename); + free((void *)default_dive_computer_device); } void set_filename(const char *filename, bool force) diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index bc829249c..17c2a4eaa 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -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,8 +322,7 @@ 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); + free(logfile_name); logfile_name = strdup(logFile.toUtf8().data()); } } @@ -351,8 +350,7 @@ 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); + free(dumpfile_name); dumpfile_name = strdup(dumpFile.toUtf8().data()); } } diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 769f486de..709693c30 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -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; - } + free((void *)existing_filename); + existing_filename = NULL; + cleanUpEmpty(); mark_divelist_changed(false); diff --git a/statistics.c b/statistics.c index ad5a95d06..2a96efb81 100644 --- a/statistics.c +++ b/statistics.c @@ -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); - } + 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); |