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:
Berthold Stoeger 2019-03-24 21:50:01 +01:00 committed by Dirk Hohndel
parent 8facd937f8
commit 04593e8ec4
11 changed files with 31 additions and 21 deletions

View file

@ -114,9 +114,9 @@ void LocationInformationWidget::updateLabels()
else
ui.diveSiteNotes->clear();
if (has_location(&diveSite->location)) {
const char *coords = printGPSCoords(&diveSite->location);
char *coords = printGPSCoords(&diveSite->location);
ui.diveSiteCoordinates->setText(coords);
free((void *)coords);
free(coords);
} else {
ui.diveSiteCoordinates->clear();
}
@ -138,10 +138,10 @@ void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
{
QString oldText = ui.diveSiteCoordinates->text();
const char *coords = printGPSCoords(&location);
char *coords = printGPSCoords(&location);
ui.diveSiteCoordinates->setText(coords);
enableLocationButtons(has_location(&location));
free((void *)coords);
free(coords);
if (oldText != ui.diveSiteCoordinates->text())
markChangedWidget(ui.diveSiteCoordinates);
}