From 5d184bd1d695b180bb559b1e1f9b1506da9d2868 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 20 Jun 2025 11:37:40 -0400 Subject: [PATCH 1/2] Fix: Potential memory leak reading AttributeStorage For unsupported domains, storage types, or other issues with reading the attribute data, the attribute name and data struct could be leaked. --- source/blender/blenkernel/intern/attribute_storage.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/attribute_storage.cc b/source/blender/blenkernel/intern/attribute_storage.cc index 4d0f6921dd4..9ff1ae6976c 100644 --- a/source/blender/blenkernel/intern/attribute_storage.cc +++ b/source/blender/blenkernel/intern/attribute_storage.cc @@ -350,6 +350,7 @@ void AttributeStorage::blend_read(BlendDataReader &reader) for (const int i : IndexRange(this->dna_attributes_num)) { ::Attribute &dna_attr = this->dna_attributes[i]; BLO_read_string(&reader, &dna_attr.name); + BLI_SCOPED_DEFER([&]() { MEM_SAFE_FREE(dna_attr.name); }); const std::optional domain = read_attr_domain(dna_attr.domain); if (!domain) { @@ -358,6 +359,7 @@ void AttributeStorage::blend_read(BlendDataReader &reader) std::optional data = read_attr_data( reader, dna_attr.storage_type, dna_attr.data_type, dna_attr); + BLI_SCOPED_DEFER([&]() { MEM_SAFE_FREE(dna_attr.data); }); if (!data) { continue; } @@ -371,9 +373,6 @@ void AttributeStorage::blend_read(BlendDataReader &reader) if (!this->runtime->attributes.add(std::move(attribute))) { CLOG_ERROR(&LOG, "Ignoring attribute with duplicate name: \"%s\"", dna_attr.name); } - - MEM_SAFE_FREE(dna_attr.name); - MEM_SAFE_FREE(dna_attr.data); } /* These fields are not used at runtime. */ From 19ef847647589cce80ccfde6a277e15c8680b2ea Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 20 Jun 2025 11:40:38 -0400 Subject: [PATCH 2/2] Fix #140689: Paint mode crash with empty Grease Pencil layer In this case an empty CurvesGeometry didn't contain the position attribute. Skipping the lookup in that case should be harmless. --- .../blender/blenkernel/intern/geometry_component_edit_data.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/blenkernel/intern/geometry_component_edit_data.cc b/source/blender/blenkernel/intern/geometry_component_edit_data.cc index 831498705f6..38aaba445f3 100644 --- a/source/blender/blenkernel/intern/geometry_component_edit_data.cc +++ b/source/blender/blenkernel/intern/geometry_component_edit_data.cc @@ -116,6 +116,9 @@ static void remember_deformed_grease_pencil_if_necessary(const GreasePencil *gre if (curves.points_num() != orig_drawing->strokes().points_num()) { continue; } + if (curves.is_empty()) { + continue; + } drawing_hints.positions_data = save_shared_attribute(curves.attributes().lookup("position")); } }