Possible memory leak in Table widget?

Hello,

I need a widget similar to the existing Table widget, but where I can insert/delete rows dynamically.

So I took a look into lv_table.c to see whether I can extend the table widget to do what I need…

I see that there already exists functionality to add rows and/or columns. But memory management when resizing looks somewhat strange to me.

I understand that ext->cell_data is a pointer to a dynamically allocated array of pointers to the cell contents. This array is resized via lv_mem_realloc() when the table gets resized. That’s fine so far.

But what about the pointers to the cell content, which were allocated in lv_table_set_call_value()? Those pointers will be lost when ext->cell_data is shrunken.

This looks like a memory leak to me. Or am I missing something here?

1 Like

(cc @kisvegabor)

I agree; it looks like a memory leak. A few months ago I made a dynamically updating table to display something for testing. The app ran out of memory after about 10 minutes. I assumed that I had a leak in my code somewhere and didn’t investigate it further since the table was just for debugging purposes. This is probably the reason for that issue. :slightly_smiling_face:

1 Like

Hi,

Thanks for the report. I’ve fixed it in the release/v7 branch.
See https://github.com/lvgl/lvgl/commit/0ce7795b7a7f0a3f7cb2f33828c739a7f9db9ea0

I’ll apply it to v8 too.

1 Like

Thanks for fixing this!

Good catch!

Since this code runs also on windows (‘simulator’), I wonder if it’s feasible to catch memory issues like this with automated tests.

E.g. https://docs.microsoft.com/en-us/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2019