Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.81k stars 146 forks source link

Fix a conditional segfault when deleting DataObject #678

Closed markozajc closed 2 months ago

markozajc commented 2 months ago

If a DataSet is loaded (for example, by evaluating planet(earth)), but not all of its properties are initialized, attempting to delete Calculator results in a segmentation fault. The following example code triggers this:

auto* calc = new Calculator(true);
calc->loadGlobalDefinitions();
calc->calculate("planet(earth)");
delete calc;

This patch adds a null check before calling MathStructure::unref() in DataObject's destructor.