mirror of
https://github.com/asterisk/asterisk.git
synced 2026-06-20 22:41:30 +00:00
d3d9e30fab
Before ast_func_read and ast_func_write call their respective read and write callbacks for registered dialplan functions, they use the module pointer in the registered ast_custom_function structure to increment the module use count. They then decrement the usecount when the callback returns. This prevents the providing module from being unloaded while there's a call using the function. Some modules, notably func_odbc, create and destroy dialplan functions based on the contents of a config file. Since the ast_custom_function structure is dynamically allocated, it could be destroyed on reload which means when the module's read or write callback returns to the ast_func calls it would try to decrement the usecount using the module pointer from an ast_custom_function structure that has already been freed. Proper locking or reference counting by the module can reduce the possibility of this happening but it can't prevent it because it doesn't have control after its read or write callback has returned to ast_func_read or ast_func_write. To address this, ast_func_read, ast_func_read2 and ast_func_write save the module pointer to a local variable before calling the module's callback, then use the saved pointer to decrement the use count. The module pointer will always be valid if the module is loaded regardless of the state of the ast_custom_function structure. Resolves: #1818