Fix: new/free mismatch in a few cases

Also see 06be295946.
These aren't all cases, but a few that I found by addding a static
assert in `MEM_new` so that it fails for trivially constructible types.
This commit is contained in:
Jacques Lucke
2024-07-09 16:22:00 +02:00
parent cad488e820
commit 056ac7f407
24 changed files with 29 additions and 27 deletions

View File

@@ -1048,7 +1048,7 @@ static bNodeTree *offset_radius_node_tree_add(ConversionData &conversion_data, L
&conversion_data.bmain, library, OFFSET_RADIUS_NODETREE_NAME, "GeometryNodeTree");
if (!group->geometry_node_asset_traits) {
group->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(__func__);
group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
}
group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;

View File

@@ -68,7 +68,7 @@ static void linestyle_copy_data(Main *bmain,
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle_src->mtex[a]) {
linestyle_dst->mtex[a] = MEM_new<MTex>(__func__);
linestyle_dst->mtex[a] = MEM_cnew<MTex>(__func__);
*linestyle_dst->mtex[a] = blender::dna::shallow_copy(*linestyle_src->mtex[a]);
}
}

View File

@@ -475,7 +475,7 @@ void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBase *nurblist, const int
VertLink *vl;
/* create new 'nurb' within the curve */
nu = MEM_new<Nurb>("MeshNurb", blender::dna::shallow_zero_initialize());
nu = MEM_cnew<Nurb>("MeshNurb", blender::dna::shallow_zero_initialize());
nu->pntsu = faces_num;
nu->pntsv = 1;

View File

@@ -2126,7 +2126,7 @@ static bNodeTree *add_auto_smooth_node_tree(Main &bmain, Library *owner_library)
bNodeTree *group = BKE_node_tree_add_in_lib(
&bmain, owner_library, DATA_("Auto Smooth"), "GeometryNodeTree");
if (!group->geometry_node_asset_traits) {
group->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(__func__);
group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
}
group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;

View File

@@ -248,7 +248,7 @@ static void ntree_copy_data(Main * /*bmain*/,
}
if (ntree_src->geometry_node_asset_traits) {
ntree_dst->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(
ntree_dst->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(
__func__, *ntree_src->geometry_node_asset_traits);
}
@@ -309,7 +309,9 @@ static void ntree_free_data(ID *id)
BKE_libblock_free_data(&ntree->id, true);
}
MEM_delete(ntree->geometry_node_asset_traits);
if (ntree->geometry_node_asset_traits) {
MEM_freeN(ntree->geometry_node_asset_traits);
}
if (ntree->nested_node_refs) {
MEM_freeN(ntree->nested_node_refs);

View File

@@ -99,7 +99,7 @@ void BKE_previewimg_free(PreviewImage **prv)
}
MEM_delete((*prv)->runtime);
MEM_delete(*prv);
MEM_freeN(*prv);
*prv = nullptr;
}
}
@@ -153,7 +153,7 @@ PreviewImage *BKE_previewimg_copy(const PreviewImage *prv)
return nullptr;
}
PreviewImage *prv_img = MEM_new<PreviewImage>(__func__, blender::dna::shallow_copy(*prv));
PreviewImage *prv_img = MEM_cnew<PreviewImage>(__func__, blender::dna::shallow_copy(*prv));
prv_img->runtime = MEM_new<blender::bke::PreviewImageRuntime>(__func__, *prv->runtime);
for (int i = 0; i < NUM_ICON_SIZES; i++) {

View File

@@ -2421,7 +2421,7 @@ static void enable_geometry_nodes_is_modifier(Main &bmain)
return true;
}
if (!group->geometry_node_asset_traits) {
group->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(__func__);
group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
}
group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;
return false;

View File

@@ -73,7 +73,7 @@ void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob)
nmd.node_group = bke::ntreeAddTree(bmain, DATA_("Surface Deform"), "GeometryNodeTree");
if (!nmd.node_group->geometry_node_asset_traits) {
nmd.node_group->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(__func__);
nmd.node_group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
}
nmd.node_group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;

View File

@@ -445,7 +445,7 @@ eWM_DragDataType BoneCollectionDragController::get_drag_type() const
void *BoneCollectionDragController::create_drag_data() const
{
ArmatureBoneCollection *drag_data = MEM_new<ArmatureBoneCollection>(__func__);
ArmatureBoneCollection *drag_data = MEM_cnew<ArmatureBoneCollection>(__func__);
*drag_data = drag_arm_bcoll_;
return drag_data;
}

View File

@@ -162,7 +162,7 @@ class LayerViewItemDragController : public AbstractViewItemDragController {
void *create_drag_data() const override
{
wmDragGreasePencilLayer *drag_data = MEM_new<wmDragGreasePencilLayer>(__func__);
wmDragGreasePencilLayer *drag_data = MEM_cnew<wmDragGreasePencilLayer>(__func__);
drag_data->node = &dragged_node_;
drag_data->grease_pencil = &grease_pencil_;
return drag_data;

View File

@@ -5323,7 +5323,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const
UI_but_funcN_set(
bt, [](bContext *, void *, void *) {}, tools_cb, nullptr);
UI_block_funcN_set(block, rna_update_cb, MEM_new<RNAUpdateCb>(__func__, cb), nullptr);
UI_block_funcN_set(block, rna_update_cb, MEM_cnew<RNAUpdateCb>(__func__, cb), nullptr);
/* The path itself */
int path_width = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X);

View File

@@ -1111,7 +1111,7 @@ static bool schedule_write_result(OGLRender *oglrender, RenderResult *rr)
return false;
}
Scene *scene = oglrender->scene;
WriteTaskData *task_data = MEM_new<WriteTaskData>("write task data");
WriteTaskData *task_data = MEM_cnew<WriteTaskData>("write task data");
task_data->rr = rr;
memcpy(&task_data->tmp_scene, scene, sizeof(task_data->tmp_scene));
BLI_mutex_lock(&oglrender->task_mutex);

View File

@@ -2133,7 +2133,7 @@ void ED_preview_restart_queue_free()
void ED_preview_restart_queue_add(ID *id, enum eIconSizes size)
{
PreviewRestartQueueEntry *queue_entry = MEM_new<PreviewRestartQueueEntry>(__func__);
PreviewRestartQueueEntry *queue_entry = MEM_cnew<PreviewRestartQueueEntry>(__func__);
queue_entry->size = size;
queue_entry->id = id;
BLI_addtail(&G_restart_previews_queue, queue_entry);

View File

@@ -2906,7 +2906,7 @@ static void paste_mtex_copybuf(ID *id)
if (mtex) {
if (*mtex == nullptr) {
*mtex = MEM_new<MTex>("mtex copy");
*mtex = MEM_cnew<MTex>("mtex copy");
}
else if ((*mtex)->tex) {
id_us_min(&(*mtex)->tex->id);

View File

@@ -531,7 +531,7 @@ static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Brush *brush = image_paint_brush(C);
GrabClone *cmv;
cmv = MEM_new<GrabClone>("GrabClone");
cmv = MEM_cnew<GrabClone>("GrabClone");
copy_v2_v2(cmv->startoffset, brush->clone.offset);
cmv->startx = event->xy[0];
cmv->starty = event->xy[1];

View File

@@ -5940,7 +5940,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
ToolSettings *settings = scene->toolsettings;
char symmetry_flag_views[BOUNDED_ARRAY_TYPE_SIZE<decltype(ps_handle->ps_views)>()] = {0};
ps_handle = MEM_new<ProjStrokeHandle>("ProjStrokeHandle");
ps_handle = MEM_cnew<ProjStrokeHandle>("ProjStrokeHandle");
ps_handle->scene = scene;
ps_handle->brush = BKE_paint_brush(&settings->imapaint.paint);

View File

@@ -322,7 +322,7 @@ static bool WIDGETGROUP_node_crop_poll(const bContext *C, wmGizmoGroupType * /*g
static void WIDGETGROUP_node_crop_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
{
NodeCropWidgetGroup *crop_group = MEM_new<NodeCropWidgetGroup>(__func__);
NodeCropWidgetGroup *crop_group = MEM_cnew<NodeCropWidgetGroup>(__func__);
crop_group->border = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr);
RNA_enum_set(crop_group->border->ptr,

View File

@@ -368,7 +368,7 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
ss << value[3];
return ss.str();
},
MEM_new<float4x4>(__func__, value),
MEM_cnew<float4x4>(__func__, value),
MEM_freeN);
}

View File

@@ -1726,7 +1726,7 @@ static bool object_mouse_select_menu(bContext *C,
if (ok) {
base_count++;
BaseRefWithDepth *base_ref = MEM_new<BaseRefWithDepth>(__func__);
BaseRefWithDepth *base_ref = MEM_cnew<BaseRefWithDepth>(__func__);
base_ref->base = base;
base_ref->depth_id = depth_id;
BLI_addtail(&base_ref_list, (void *)base_ref);
@@ -1966,7 +1966,7 @@ static bool bone_mouse_select_menu(bContext *C,
if (!is_duplicate_bone) {
bone_count++;
BoneRefWithDepth *bone_ref = MEM_new<BoneRefWithDepth>(__func__);
BoneRefWithDepth *bone_ref = MEM_cnew<BoneRefWithDepth>(__func__);
bone_ref->base = bone_base;
bone_ref->bone_ptr = bone_ptr;
bone_ref->depth_id = hit_result.depth;

View File

@@ -1829,7 +1829,7 @@ static void geometry_node_asset_trait_flag_set(PointerRNA *ptr,
{
bNodeTree *ntree = static_cast<bNodeTree *>(ptr->data);
if (!ntree->geometry_node_asset_traits) {
ntree->geometry_node_asset_traits = MEM_new<GeometryNodeAssetTraits>(__func__);
ntree->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
}
SET_FLAG_FROM_TEST(ntree->geometry_node_asset_traits->flag, value, flag);
}

View File

@@ -88,7 +88,7 @@ static void draw_item(uiList * /*ui_list*/,
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
static const uiListType *items_list = []() {
uiListType *list = MEM_new<uiListType>(__func__);
uiListType *list = MEM_cnew<uiListType>(__func__);
STRNCPY(list->idname, "NODE_UL_capture_items_list");
list->draw_item = draw_item;
WM_uilisttype_add(list);

View File

@@ -377,7 +377,7 @@ static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
bNode &node = *static_cast<bNode *>(ptr->data);
static const uiListType *menu_items_list = []() {
uiListType *list = MEM_new<uiListType>(__func__);
uiListType *list = MEM_cnew<uiListType>(__func__);
STRNCPY(list->idname, "NODE_UL_enum_definition_items");
list->draw_item = draw_menu_switch_item;
WM_uilisttype_add(list);

View File

@@ -66,7 +66,7 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext * /*C*/
static void node_shader_init_tex_pointdensity(bNodeTree * /*ntree*/, bNode *node)
{
NodeShaderTexPointDensity *point_density = MEM_new<NodeShaderTexPointDensity>("new pd node");
NodeShaderTexPointDensity *point_density = MEM_cnew<NodeShaderTexPointDensity>("new pd node");
point_density->resolution = 100;
point_density->radius = 0.3f;
point_density->space = SHD_POINTDENSITY_SPACE_OBJECT;

View File

@@ -208,7 +208,7 @@ wmJob *WM_jobs_get(wmWindowManager *wm,
wm_job->main_thread_mutex = BLI_ticket_mutex_alloc();
WM_job_main_thread_lock_acquire(wm_job);
wm_job->worker_status.reports = MEM_new<ReportList>(__func__);
wm_job->worker_status.reports = MEM_cnew<ReportList>(__func__);
BKE_reports_init(wm_job->worker_status.reports, RPT_STORE | RPT_PRINT);
BKE_report_print_level_set(wm_job->worker_status.reports, RPT_WARNING);
}