File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -396,9 +396,14 @@ PyType *PyMemoryView::static_type() const { return types::memoryview(); }
396396void PyMemoryView::visit_graph (Visitor &visitor)
397397{
398398 PyObject::visit_graph (visitor);
399- if (m_view.obj && !m_view.readonly ) { visitor.visit (*m_view.obj ); }
400- if (m_managed_buffer && m_managed_buffer->m_main_view .obj
401- && !m_managed_buffer->m_main_view .readonly ) {
399+ // A view must root its backing object whether or not it is readonly: readonly
400+ // governs writing *through* the view, not whether the view holds a reference.
401+ // Because a memoryview over immutable bytes is always readonly, skipping those
402+ // left BufferedWriter::raw_write's PyBytes unrooted - it was collected during
403+ // the allocations that follow, and the raw stream then copied recycled memory.
404+ // Reproduces with --gc-frequency 1.
405+ if (m_view.obj ) { visitor.visit (*m_view.obj ); }
406+ if (m_managed_buffer && m_managed_buffer->m_main_view .obj ) {
402407 visitor.visit (*m_managed_buffer->m_main_view .obj );
403408 }
404409}
You can’t perform that action at this time.
0 commit comments