顯式刪除托管指針將導致程序崩潰或無法正常運行。
刪除托管指針后,如果指針管理代碼假設該指針仍然有效,將引發程序崩潰或執行錯誤的操作。以下示例可說明這一錯誤。
std::auto_ptr<foo> p(new foo);
foo* rawFoo = p.get();
delete rawFoo;
delete 之前將指針從管理類中分離出來,則管理類知道以后不再使用該指針。
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A9 Application Denial of Service
[2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP6080 CAT II
[3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP6080 CAT II
[4] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 730
[5] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.9