AP_Scripting: Fix memory leak in LUA dataflash logging
Before change, memory use grew linearly over time.
After change, memory use was constant.
I'm not just throwing stuff at the wall. This is correct.
This PR indeed fixes an error in the accounting which might create that impression, but as far as I can tell there is no actual leak and I would like to confirm. How did you check?
By setting SCR_DEBUG_OPTS to 2 and watching memory increase, and then making this change and watching memory not increase.
Yes, that would show the accounting bug. But there is still no actual leak that I can tell.
In any case, there are several other places in this function that call luaM_free that also need a fix, so this PR needs revision.
Consider instead refactoring to use luaL_Buffer and luaL_buffinitsize. Then you can get rid of all the free calls, it is safe to abandon it.
In fact, please just make it a static 256 byte buffer. We can't have a message longer than that. Well we could, but that is a pre-existing bug that is broken with this.
Wrong button...
Thanks for reporting this. Should be fixed in that other PR.