diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index 358af7d32..6970a4fe6 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -11,14 +11,20 @@ Graph::Function::Function(const char * text, KDColor color) : } void Graph::Function::setContent(const char * c) { - #if __GLIBC__ +#if __GLIBC__ // FIXME: This is ugly. strncpy(m_text, c, sizeof(m_text)); #else strlcpy(m_text, c, sizeof(m_text)); #endif - m_expression = expression(); - m_layout = layout(); + if (m_expression != nullptr) { + delete m_expression; + } + m_expression = Expression::parse(m_text); + if (m_layout != nullptr) { + delete m_layout; + } + m_layout = expression()->createLayout(); } void Graph::Function::setColor(KDColor color) { @@ -26,7 +32,6 @@ void Graph::Function::setColor(KDColor color) { } Graph::Function::~Function() { - //FIXME: Free m_text! if (m_layout != nullptr) { delete m_layout; } @@ -44,16 +49,10 @@ const char * Graph::Function::name() { } Expression * Graph::Function::expression() { - if (m_expression == nullptr) { - m_expression = Expression::parse(m_text); - } return m_expression; } ExpressionLayout * Graph::Function::layout() { - if (m_layout == nullptr) { - m_layout = expression()->createLayout(); - } return m_layout; }