ardupilot icon indicating copy to clipboard operation
ardupilot copied to clipboard

AP_Scripting: Fix memory leak in LUA dataflash logging

Open jschall opened this issue 1 month ago • 6 comments

jschall avatar Dec 03 '25 20:12 jschall

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.

jschall avatar Dec 03 '25 22:12 jschall

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?

tpwrules avatar Dec 03 '25 23:12 tpwrules

By setting SCR_DEBUG_OPTS to 2 and watching memory increase, and then making this change and watching memory not increase.

jschall avatar Dec 03 '25 23:12 jschall

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.

tpwrules avatar Dec 03 '25 23:12 tpwrules

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.

tpwrules avatar Dec 05 '25 04:12 tpwrules

Wrong button...

tpwrules avatar Dec 05 '25 04:12 tpwrules

Thanks for reporting this. Should be fixed in that other PR.

tpwrules avatar Dec 15 '25 20:12 tpwrules