Content deleted Content added
→Resource leak: "execute around", AOP |
m →Resource leak: typo |
||
Line 14:
{{main|resource leak}}
Formally, resource management (preventing resource leaks) consists of ensuring that a resource is released if and only if it is successfully acquired. This general problem can be abstracted as "''before,'' ''body,'' and ''after''" code, which normally are executed in this order, with the condition that the ''after'' code is called if and only if the ''before'' code successfully completes, regardless of whether the ''body'' code executes successfully or not. This is also known as ''execute around''{{sfn|Beck|1997|37–39}} or a ''code sandwich,'' and occurs in various other contexts,{{sfn|Elder|Jackson|Liblit|2008|p=3}} such as a temporary change of program state, or [[Tracing (software)|tracing]] entry and exit into a [[subroutine]]. However, resource management is the most commonly cited application. In [[
In the terminology of [[control flow analysis]], resource release must [[postdominate]] successful resource acquisition;{{sfn|Elder|Jackson|Liblit|2008|p=2}} failure to ensure this is a bug, and a code path that violates this condition causes a resource leak. Resource leaks are often minor problems, generally not crashing the program, but instead causing some slowdown to the program or the overall system.{{sfn|Elder|Jackson|Liblit|2008|p=3}} However, they may cause crashes – either the program itself or other programs – due to ''resource exhaustion:'' if the system runs out of resources, acquisition requests fail. This can present a [[security bug]] if an attack can cause resource exhaustion. Resource leaks may happen under regular program flow – such as simply forgetting to release a resource – or only in exceptional circumstances, such as when a resource is not released if there is an exception in another part of the program. Resource leaks are very frequently caused by [[Structured programming#Early exit|early exit]] from a subroutine, either by a <code>return</code> statement, or an exception raised either by the subroutine itself, or a deeper subroutine that it calls. While resource release due to return statements can be handled by carefully releasing within the subroutine before the return, exceptions cannot be handled without some additional language facility that guarantees that release code is executed.
|