OnionUI / Onion

OS overhaul for Miyoo Mini and Mini+
https://onionui.github.io
GNU General Public License v3.0
3.46k stars 215 forks source link

Common `file.c` util leaks #1661

Open MattCatz opened 2 months ago

MattCatz commented 2 months ago

Because file_read allocates memory, it should be free-ed. Currently, attempting to do so will cause a compiler warning since free does not take const qualified pointer (because we are modifying the memory).

Changing the return type to char * rather than const char * will allow the caller to correctly free memory.

Also fix most of the transitive leaks I could find. e.x. strdup returns allocated memory that should be free-ed.

Last patch doesn't really fix anything but adds the malloc function attribute for the compiler but also to hint to developers that the function allocates memory that needs to be free-ed.