Craft icon indicating copy to clipboard operation
Craft copied to clipboard

Potential memory leak.

Open rachyyyy opened this issue 3 years ago • 3 comments

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

rachyyyy avatar Sep 03 '22 07:09 rachyyyy

zSql is freed in line 2375

OctavioAnino avatar Sep 27 '22 04:09 OctavioAnino

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.

rachyyyy avatar Sep 27 '22 11:09 rachyyyy

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.

OctavioAnino avatar Sep 27 '22 15:09 OctavioAnino