-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing modules wthich don't use the Lua memory allocator #2303
Comments
I'm thinking that the easiest (although nasty) approach to this is to define a malloc/free wrapper over the lua allocator which allocates using the lua allocator, then stuffs the block into a table indexed by the memory address of the userdata. Then on free we can find the block in our table and remove that entry. I think that would preserve the correct semantics (apart from the out-of-memory condition when malloc would return NULL, and this approach would panic the system. This may not be bad as I bet that most places don't handle the out of memory condition gracefully) |
Of course, this still leaves the espressif core libraries which will continue to use their own malloc/free and maybe those do get it right. |
If you look at the code in Oh, yes, whilst I think on the othe tweek that I would do would be to change the panic handler so that instead of just rebooting on stopping an uncaught error. it prints out the error traceback first so at least the developer can see where the uncaught error occurted. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Just some updates to note:
LwIP, unfortunately, uses raw |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The following modules include bare malloc / free API calls:
coap
,crypto
,enduser_setup
,file
,http
,mqtt
,net
,pcm
,rotary
,sntp
,sqlite3
,tls
,tm1829
,u8g_glue
,websocket
,wifi
,wifi_eventmon
,wifi_monitor
,ws2812
.The lua allocator should always be used in Lua modules. The reason for this is that the Lua allocator is a thin wrapper on top of the standard allocator, but handles out of memory conditions differently. If this occurs, the Lua system runs the GC and then retries the allocation. It only fails is there there is not enough memory at this point. Also instead of returning a null pointer, a Lua error is thrown.
Expected behavior
Libraries should not raise a memory allocation error if the EGC mode
ON_ALLOC_FAILURE
is set and enough memory is available after GC to satisfy the allocation.Actual behavior
The application can crash with an out of memory error even though there is enough heap available to satisfay the request.
NodeMCU version
master
anddev
The text was updated successfully, but these errors were encountered: