From 04593e8ec4bac2606dec54605c72a6a49cc83f9b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 24 Mar 2019 21:50:01 +0100 Subject: 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 --- core/subsurface-qt/DiveObjectHelper.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/subsurface-qt') diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 0742e382f..921d55bea 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -112,7 +112,12 @@ QString DiveObjectHelper::location() const QString DiveObjectHelper::gps() const { 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 -- cgit v1.2.3-70-g09d2