fogleman / Craft

A simple Minecraft clone written in C using modern OpenGL (shaders).
http://www.michaelfogleman.com/craft/
MIT License
10.44k stars 1.39k forks source link

Potential memory leak. #299

Open rachyyyy opened 2 years ago

rachyyyy commented 2 years ago

Potential memory leak in shell.c line 2357. The while loop is executed without releasing Zsql will cause a memory leak. Doc says "The sqlite3_mprintf() and sqlite3_vmprintf() routines write their results into memory obtained from sqlite3_malloc64(). The strings returned by these two routines should be released by sqlite3_free()." Using sqlite3_free() to free zSql will prevent the memory leak.

1662191655452

OctavioAnino commented 2 years ago

zSql is freed in line 2375

rachyyyy commented 2 years ago

zSql is freed in line 2375

For all the mprintf() called in while loop (line 2357 and line 2364), the zSql should be freed after the while loop and before line 2373. Otherwise, there will be a potential memory leak.

OctavioAnino commented 2 years ago

You're right, my bad. This is also in contrast with what is seen throughout the rest of the file- were every pointer returned by mprintf() is indeed eventually freed. Of course, except the ones in this issue.