whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.18k stars 221 forks source link

memory leak in can.receive #375

Closed chowette closed 3 years ago

chowette commented 3 years ago

There is a memory leak in can.receive when there is an error ( either not initialized or timeout )

Running this code will eventually reboot with a heap corruption


-- can.attach(can.CAN0, 500)  -- optional

while true do
    pcall( function()
        can.receive(can.CAN0, 0) -- 0 msec timeout
    end )
    os.stats()
end
the0ne commented 3 years ago

only thing I can guess would be the alloc in line 132 of ./sys/drivers/can.c buffer = malloc(40);

that I had actually expected to be free'd in some driver-error free() call.

jolivepetrus commented 3 years ago

Solved in https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/2562d7028bb175aba29332702ee9bd0810c49e91 and https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/a5f7cf743af1cc8727a8332ba5e029e9e60a90ba.