MantisBT - Open CASCADE
View Issue Details
0026698Open CASCADE[OCCT] OCCT:Codingpublic2015-09-17 10:172020-09-11 15:34
[OCCT] 7.6.0* 
0026698: Coding - Avoid usage of non-guarded pointers to dynamically allocated memory
It is quite widespread in OCCT code, especially in modeling, to use plain C pointers to manage memory allocated dynamically, with explicit calls to new/malloc and delete/free. This is unsafe and bad practice, leading to memory leaks detected regularly (see e.g. #26616 as the most recent case), which must be eliminated. The natural and recommended way to deal with dynamically allocated memory is usage of smart pointers, typically OCCT Handles.

Note that before OCCT 7.0 it was not always easy to use Handles to classes not inheriting Standard_Transient, especially for fields of CDL classes, due to non-trivial actions required. Now it should be quite easy to wrap any class to NCollection_Shared<> template and then manipulate it by Handle.

There is however a potential issue when using Handles: they are not suitable for cases when memory is allocated via non-standard allocators (such as NCollection_IncAllocator). This is a problem to be investigated. Until it is resolved, std::shared_ptr<> with allocator argument could be used in such cases.
No tags attached.
parent of 0026915closed bugmaster Open CASCADE Visualization - return Handle from Graphic3d_CView::FBOCreate() instead of a pointer 
related to 0029442new abv Open CASCADE NCollection_Shared is unable to wrap classes without default constructor 
related to 0030603closed bugmaster Community Memory Leaks in Geom_BSplineCurve 
Issue History
2015-09-17 10:17abvNew Issue
2015-09-17 10:17abvAssigned To => kgv
2015-11-17 16:59kgvTarget Version7.0.0 => 7.1.0
2015-11-23 13:22kgvRelationship addedparent of 0026915
2016-09-23 12:24abvAssigned Tokgv => ski
2016-09-23 12:24abvStatusnew => assigned
2016-11-03 17:38abvTarget Version7.1.0 => 7.2.0
2017-07-20 12:29kgvTarget Version7.2.0 => 7.3.0
2018-01-18 17:13msvAssigned Toski => isn
2018-01-22 18:02isnRelationship addedrelated to 0029442
2018-02-25 23:12abvTarget Version7.3.0 => 7.4.0
2019-03-25 14:03BenjaminBihlerRelationship addedrelated to 0030603
2019-07-10 19:27abvTarget Version7.4.0 => 7.5.0
2020-09-11 15:34utverdovTarget Version7.5.0 => 7.6.0*

There are no notes attached to this issue.