Skip to content

Commit 253538f

Browse files
committed
Fix page buffer memory leak if setting codec twice
A page buffer of a codec is allocated when the codec is set to Btree. However, if the same codec was set to Btree again, then the pointer to the page buffer got simply overwitten with a pointer to newly allocated page buffer. Thus, the old page buffer memory was leaked. This commit adds missing sqlite3_free() call when setting a codec multiple times.
1 parent 695bc40 commit 253538f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sqleet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ static int codec_set_to(Codec *codec, Btree *pBt)
402402

403403
/* Prepare codec */
404404
if (codec) {
405+
if (codec->pagebuf)
406+
sqlite3_free(codec->pagebuf);
405407
if (!codec->pagesize)
406408
codec->pagesize = sqlite3BtreeGetPageSize(pBt);
407409
if (!(codec->pagebuf = sqlite3_malloc(codec->pagesize))) {

0 commit comments

Comments
 (0)