mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-03 15:43:09 +00:00
Cleanup: fix printGPSCoords signature and leaks
The printGPSCoords() function returns a copied C-style string. Since the owndership is transferred to the caller, the correct return type is "char *" instead of "const char *". Thus a number of casts when calling free can be removed. Moreover a number of callers didn't free the string and thus were leaking memory. Fix them. Ultimately we might want two versions of the function: one for QString, one for C-style strings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8facd937f8
commit
04593e8ec4
11 changed files with 31 additions and 21 deletions
|
@ -137,7 +137,9 @@ QString GpsLocation::currentPosition()
|
||||||
if (delta < 300) {
|
if (delta < 300) {
|
||||||
// we can simply use the last position that we tracked
|
// we can simply use the last position that we tracked
|
||||||
gpsTracker gt = m_trackers.last();
|
gpsTracker gt = m_trackers.last();
|
||||||
QString gpsString = printGPSCoords(>.location);
|
char *gps = printGPSCoords(>.location);
|
||||||
|
QString gpsString = gps;
|
||||||
|
free(gps);
|
||||||
qDebug() << "returning last position" << gpsString;
|
qDebug() << "returning last position" << gpsString;
|
||||||
return gpsString;
|
return gpsString;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -164,10 +164,10 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
||||||
dive->dive_site = ds;
|
dive->dive_site = ds;
|
||||||
} else {
|
} else {
|
||||||
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
|
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
|
||||||
const char *coords = printGPSCoords(&location);
|
char *coords = printGPSCoords(&location);
|
||||||
// we have a dive site that already has GPS coordinates
|
// we have a dive site that already has GPS coordinates
|
||||||
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
||||||
free((void *)coords);
|
free(coords);
|
||||||
}
|
}
|
||||||
ds->location = location;
|
ds->location = location;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1201,9 +1201,9 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
|
||||||
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
||||||
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
||||||
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
||||||
const char *coords = printGPSCoords(&location);
|
char *coords = printGPSCoords(&location);
|
||||||
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords);
|
||||||
free((void *)coords);
|
free(coords);
|
||||||
} else {
|
} else {
|
||||||
ds->location = location;
|
ds->location = location;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ QString distance_string(int distanceInMeters)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" const char *printGPSCoords(const location_t *location)
|
extern "C" char *printGPSCoords(const location_t *location)
|
||||||
{
|
{
|
||||||
int lat = location->lat.udeg;
|
int lat = location->lat.udeg;
|
||||||
int lon = location->lon.udeg;
|
int lon = location->lon.udeg;
|
||||||
|
|
|
@ -123,7 +123,7 @@ void moveInVector(Vector &v, int rangeBegin, int rangeEnd, int destination)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *printGPSCoords(const location_t *loc);
|
char *printGPSCoords(const location_t *loc);
|
||||||
bool in_planner();
|
bool in_planner();
|
||||||
bool getProxyString(char **buffer);
|
bool getProxyString(char **buffer);
|
||||||
bool canReachCloudServer();
|
bool canReachCloudServer();
|
||||||
|
|
|
@ -112,7 +112,12 @@ QString DiveObjectHelper::location() const
|
||||||
QString DiveObjectHelper::gps() const
|
QString DiveObjectHelper::gps() const
|
||||||
{
|
{
|
||||||
struct dive_site *ds = m_dive->dive_site;
|
struct dive_site *ds = m_dive->dive_site;
|
||||||
return ds ? QString(printGPSCoords(&ds->location)) : QString();
|
if (!ds)
|
||||||
|
return QString();
|
||||||
|
char *gps = printGPSCoords(&ds->location);
|
||||||
|
QString res = gps;
|
||||||
|
free(gps);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiveObjectHelper::gps_decimal() const
|
QString DiveObjectHelper::gps_decimal() const
|
||||||
|
|
|
@ -114,9 +114,9 @@ void LocationInformationWidget::updateLabels()
|
||||||
else
|
else
|
||||||
ui.diveSiteNotes->clear();
|
ui.diveSiteNotes->clear();
|
||||||
if (has_location(&diveSite->location)) {
|
if (has_location(&diveSite->location)) {
|
||||||
const char *coords = printGPSCoords(&diveSite->location);
|
char *coords = printGPSCoords(&diveSite->location);
|
||||||
ui.diveSiteCoordinates->setText(coords);
|
ui.diveSiteCoordinates->setText(coords);
|
||||||
free((void *)coords);
|
free(coords);
|
||||||
} else {
|
} else {
|
||||||
ui.diveSiteCoordinates->clear();
|
ui.diveSiteCoordinates->clear();
|
||||||
}
|
}
|
||||||
|
@ -138,10 +138,10 @@ void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
|
||||||
{
|
{
|
||||||
QString oldText = ui.diveSiteCoordinates->text();
|
QString oldText = ui.diveSiteCoordinates->text();
|
||||||
|
|
||||||
const char *coords = printGPSCoords(&location);
|
char *coords = printGPSCoords(&location);
|
||||||
ui.diveSiteCoordinates->setText(coords);
|
ui.diveSiteCoordinates->setText(coords);
|
||||||
enableLocationButtons(has_location(&location));
|
enableLocationButtons(has_location(&location));
|
||||||
free((void *)coords);
|
free(coords);
|
||||||
if (oldText != ui.diveSiteCoordinates->text())
|
if (oldText != ui.diveSiteCoordinates->text())
|
||||||
markChangedWidget(ui.diveSiteCoordinates);
|
markChangedWidget(ui.diveSiteCoordinates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,9 +484,9 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bottomText.isEmpty()) {
|
if (bottomText.isEmpty()) {
|
||||||
const char *gpsCoords = printGPSCoords(&ds->location);
|
char *gpsCoords = printGPSCoords(&ds->location);
|
||||||
bottomText = QString(gpsCoords);
|
bottomText = QString(gpsCoords);
|
||||||
free( (void*) gpsCoords);
|
free(gpsCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
|
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
|
||||||
|
|
|
@ -411,9 +411,9 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
|
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
|
||||||
|
|
||||||
if (ui.locationTags->text().isEmpty() && has_location(&ds->location)) {
|
if (ui.locationTags->text().isEmpty() && has_location(&ds->location)) {
|
||||||
const char *coords = printGPSCoords(&ds->location);
|
char *coords = printGPSCoords(&ds->location);
|
||||||
ui.locationTags->setText(coords);
|
ui.locationTags->setText(coords);
|
||||||
free((void *)coords);
|
free(coords);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ui.location->clear();
|
ui.location->clear();
|
||||||
|
|
|
@ -246,10 +246,10 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form
|
||||||
bool savep = prefs.coordinates_traditional;
|
bool savep = prefs.coordinates_traditional;
|
||||||
prefs.coordinates_traditional = formatTraditional;
|
prefs.coordinates_traditional = formatTraditional;
|
||||||
location_t location = mk_location(coord);
|
location_t location = mk_location(coord);
|
||||||
const char *coordinates = printGPSCoords(&location);
|
char *coordinates = printGPSCoords(&location);
|
||||||
QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard);
|
QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard);
|
||||||
|
|
||||||
free((void *)coordinates);
|
free(coordinates);
|
||||||
prefs.coordinates_traditional = savep;
|
prefs.coordinates_traditional = savep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1602,9 +1602,12 @@ QString QMLManager::getGpsFromSiteName(const QString& siteName)
|
||||||
struct dive_site *ds;
|
struct dive_site *ds;
|
||||||
|
|
||||||
ds = get_dive_site_by_name(qPrintable(siteName));
|
ds = get_dive_site_by_name(qPrintable(siteName));
|
||||||
if (ds)
|
if (!ds)
|
||||||
return QString(printGPSCoords(&ds->location));
|
|
||||||
return QString();
|
return QString();
|
||||||
|
char *gps = printGPSCoords(&ds->location);
|
||||||
|
QString res = gps;
|
||||||
|
free(gps);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::setNotificationText(QString text)
|
void QMLManager::setNotificationText(QString text)
|
||||||
|
|
Loading…
Reference in a new issue