[PATCH 1/2] Make 'clear_dive()' free the primary dive computer data properly

Linus Torvalds torvalds at linux-foundation.org
Thu Jun 9 17:19:05 PDT 2016


[ Sorry if you get this twice, I had trouble with gmail, I'm not sure
if the first copy made it out or not ]

On Thu, Jun 9, 2016 at 4:53 PM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> I'll try to see what I can get, but can you let me know exactly what
> your sequence was? I tried opening an empty file, then plan a dive and
> cancel it immediately. That didn't fail, but the *second* time I did
> it I got the problem.

Ok, I think I found it.

The dive planner does

    displayed_dive.dc.model = model;

where "model" is a just a pointer to the static string "planned dive".
Although it can be "manually added dive" too for that case.

That assignment should just do "strdup()" on the passed-in string.

A patch something like the attached fixes it here.  But maybe you're
seeing a different issue, so please double-check..

            Linus
-------------- next part --------------
 desktop-widgets/mainwindow.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 6542a3ead49f..15f34e616890 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -890,7 +890,7 @@ void MainWindow::setupForAddAndPlan(const char *model)
 	clear_dive_site(&displayed_dive_site);
 	displayed_dive.id = dive_getUniqID(&displayed_dive);
 	displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
-	displayed_dive.dc.model = model; // don't translate! this is stored in the XML file
+	displayed_dive.dc.model = strdup(model); // don't translate! this is stored in the XML file
 	// setup the dive cylinders
 	DivePlannerPointsModel::instance()->clear();
 	DivePlannerPointsModel::instance()->setupCylinders();


More information about the subsurface mailing list