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 <pestophagous@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
K. \"pestophagous\" Heller 2015-12-03 21:42:23 -08:00 committed by Dirk Hohndel
parent b0063e5d1a
commit 2778470b97
4 changed files with 26 additions and 4 deletions

View file

@ -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);