OnionIoT / lv_example

A template for Omega2 Dash programs using the LittleV Graphics Library
MIT License
5 stars 1 forks source link

Memory leak in main event loop #1

Closed troyhebe closed 4 years ago

troyhebe commented 4 years ago

When I run this example code on the Onion Omega2 Dash. I have a problem that the main event loop causes a memory leak. Since it gets run every 5ms it continue to allocate memory until the program finally crashes. Simply commenting out the lv_tick_inc prevents the memory leak. Even stripping down the code to only initialize and register the display driver and input device followed by the main event loop shows the issue.

troyhebe commented 4 years ago

The problem is actually in the XPT7603 driver. The function xpt7603_read is registered as the callback and gets called by the lv_task_handler() every 5ms. That function in turn calls om_read_gpio() which does this mmap:

    regAddress = (unsigned long int*)mmap   (       NULL,
                                             1024,
                                             PROT_READ|PROT_WRITE,
                                             MAP_FILE|MAP_SHARED,
                                             m_mfd,
                                             GPIO_REG_BLOCK_ADDR
                                             );

The problem is that it does not do an munmap and thus leaks 1k on every callback. Throwing in a munmap is a quick and dirty workaround. However, it is opening /dev/mem and doing the mmap in order to get the "regAddrOffset" address but that address does not change so it really does not make sense to be opening /dev/mem and doing an mmap in every invocation of the callback handler. Perhaps a more complete fix would be to only get the regAddrOffset when the driver is first initialized?

greenbreakfast commented 4 years ago

Ah good find! Agreed, not opening /dev/mem and doing an mmap in every invocation of the callback hander, would be the best solution.

Could you please submit a PR in the lv_drivers repo?

troyhebe commented 4 years ago

Unfortunately, the issue tracking feature seems to be disabled for that repo so I could not move this issues to that repo. A PR has been created to resolve this issue.

greenbreakfast commented 4 years ago

Looks like forked repos have issues disabled by default. I've gone ahead and enabled them on OnionIoT/lv_drivers.

I've also tested the fix and merged the PR. Along with that, the lv_drivers submodule in this repo has been updated to point to the latest commit.

Thanks for the contribution!

greenbreakfast commented 4 years ago

Update on this: I've been running the updated program on an Omega2 Dash unit since Friday night. Still running fine!