From 2778470b9755af2349a70f127e208750afda7725 Mon Sep 17 00:00:00 2001 From: "K. \\\"pestophagous\\\" Heller" Date: Thu, 3 Dec 2015 21:42:23 -0800 Subject: Prevent gaschange tank icons from using garbage coords. Tank icons were shown at incorrect spots on the profile when the DiveEventItem object held a pointer to a struct event even after the struct event at that address had been freed. When internalEvent is a pointer to freed memory, internalEvent->time.seconds could have all kinds of crazy values, which get used in member function DiveEventItem::recalculatePos to place the tank at bad x coordinates. The DiveEventItem(s) no longer store a pointer to memory that they do not own. This way, no matter how the path of execution arrives into slot recalculatePos, we never need fear that the DiveEventItem will dereference a garbage pointer to a struct event. Fixes #968 Signed-off-by: K. Heller Signed-off-by: Dirk Hohndel --- profile-widget/diveeventitem.cpp | 8 +++++++- profile-widget/diveeventitem.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'profile-widget') diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 0bbc84267..083c8b5b8 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -19,6 +19,10 @@ DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent), setFlag(ItemIgnoresTransformations); } +DiveEventItem::~DiveEventItem() +{ + free(internalEvent); +} void DiveEventItem::setHorizontalAxis(DiveCartesianAxis *axis) { @@ -48,7 +52,9 @@ void DiveEventItem::setEvent(struct event *ev) { if (!ev) return; - internalEvent = ev; + + free(internalEvent); + internalEvent = clone_event(ev); setupPixmap(); setupToolTipString(); recalculatePos(true); diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h index f358fee6d..9d6ad5d26 100644 --- a/profile-widget/diveeventitem.h +++ b/profile-widget/diveeventitem.h @@ -11,6 +11,7 @@ class DiveEventItem : public DivePixmapItem { Q_OBJECT public: DiveEventItem(QObject *parent = 0); + virtual ~DiveEventItem(); void setEvent(struct event *ev); struct event *getEvent(); void eventVisibilityChanged(const QString &eventName, bool visible); -- cgit v1.2.3-70-g09d2