KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_rule_area_destruction.cpp File Reference

Regression test for issue 22822: crash when closing eeschema while background library loading is in progress. More...

#include <qa_utils/wx_utils/unit_test_utils.h>
#include <schematic.h>
#include <sch_label.h>
#include <sch_line.h>
#include <sch_pin.h>
#include <sch_rule_area.h>
#include <sch_screen.h>
#include <sch_symbol.h>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (RuleAreaDestroyedBeforeContainedItems)
 Verify that destroying a rule area before its contained items does not crash.
 
 BOOST_AUTO_TEST_CASE (ContainedItemsDestroyedBeforeRuleArea)
 Verify that destroying contained items before the rule area also works.
 
 BOOST_AUTO_TEST_CASE (CacheRefreshClearsReciprocalLinks)
 Verify that rebuilding rule area caches clears reciprocal links on owned children and directive labels which are no longer attached to the area.
 

Detailed Description

Regression test for issue 22822: crash when closing eeschema while background library loading is in progress.

The crash occurs in SCH_RULE_AREA::RemoveItem() because FreeDrawList() deletes items in arbitrary order. If a rule area is destroyed before items it contains, those items' destructors call RemoveItem() on freed memory.

Definition in file test_sch_rule_area_destruction.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( CacheRefreshClearsReciprocalLinks )

Verify that rebuilding rule area caches clears reciprocal links on owned children and directive labels which are no longer attached to the area.

Definition at line 114 of file test_sch_rule_area_destruction.cpp.

References SCH_SCREEN::Append(), pin, and SCH_RULE_AREA::UpdateRuleAreasInScreens().

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( ContainedItemsDestroyedBeforeRuleArea )

Verify that destroying contained items before the rule area also works.

The reverse ordering should also be safe since SCH_ITEM::~SCH_ITEM calls RemoveItem on still-valid rule areas.

Definition at line 85 of file test_sch_rule_area_destruction.cpp.

References BOOST_CHECK_EQUAL(), and LAYER_WIRE.

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( RuleAreaDestroyedBeforeContainedItems )

Verify that destroying a rule area before its contained items does not crash.

This reproduces the exact destruction ordering that caused the issue 22822 segfault in FreeDrawList().

Definition at line 50 of file test_sch_rule_area_destruction.cpp.

References BOOST_AUTO_TEST_CASE(), BOOST_CHECK_EQUAL(), and LAYER_WIRE.