There is a bug in the InnoDB SPATIAL INDEX code, in the function rtr_adjust_upper_level(). The mem_heap_t object where node_ptr_upper was created is being passed to btr_cur_pessimistic_insert(). The function mem_heap_empty() may be invoked if the upper-level page needs to be split. That could cause the node_ptr_upper to be corrupted.
This was brought to our attentio by the MySQL 5.7.30 fix of
Bug #29465567 INNODB: RTREE SPLIT ASSERTION FAILURE.
The fix includes a test case and some additional debug instrumentation. I would rely on the mem_heap_t instrumentation that we have in MariaDB, and try to avoid additional debug code.