_alloca allocates size bytes from the program stack. The allocated space is automatically freed when the calling function exits (not when the allocation merely passes out of scope). Therefore, do not pass the pointer value returned by _alloca as an argument to free.
There are restrictions to explicitly calling _alloca in an exception handler (EH). EH routines that run on x86-class processors operate in their own memory frame: They perform their tasks in memory space that is not based on the current location of the stack pointer of the enclosing function. The most common implementations include Windows NT structured exception handling (SEH) and C++ catch clause expressions. Therefore, explicitly calling _alloca in any of the following scenarios results in program failure during the return to the calling EH routine:
Windows NT SEH exception filter expression: __except (_alloca () )
Windows NT SEH final exception handler: __finally {_alloca () }
C++ EH catch clause expression
However, _alloca can be called directly from within an EH routine or from an application-supplied callback that gets invoked by one of the EH scenarios previously listed.
Security Note: |
|---|
In Windows XP, if
_alloca is called inside a try/catch block, you must call _resetstkoflw in the catch block.
|
In addition to the above restrictions, when using the/clr (Common Language Runtime Compilation) option, _alloca cannot be used in __except blocks. For more information, see /clr Restrictions.