-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Update to the latest version of SQLite3 to fix memory leaks #694
base: main
Are you sure you want to change the base?
Conversation
Shouldn't this be fixed in the upstream sqlite repository? I am hesitant to accept this because I assume the sqlite code is solid and if there is a memory leak is probably because I have messed up somewhere in my code. |
I just checked, and it's already fixed in the sqlite repository: static void *sqlite3MemRealloc(void *pPrior, int nByte){
struct MemBlockHdr *pOldHdr;
void *pNew;
assert( mem.disallow==0 );
assert( (nByte & 7)==0 ); /* EV: R-46199-30249 */
pOldHdr = sqlite3MemsysGetHeader(pPrior);
pNew = sqlite3MemMalloc(nByte);
if( pNew ){
memcpy(pNew, pPrior, (int)(nByte<pOldHdr->iSize ? nByte : pOldHdr->iSize));
if( nByte>pOldHdr->iSize ){
randomFill(&((char*)pNew)[pOldHdr->iSize], nByte - (int)pOldHdr->iSize);
}
sqlite3MemFree(pPrior);
}
return pNew;
} This suggests that there is actually a memory leak. I guess the proper fix here is to just update to the latest |
03eb2bd
to
eaf3ed9
Compare
sqlite3MemRealloc
@ahrm I've updated the original PR description. |
Hello everyone. First, I am glad someone pointed this bug out, this memory leak makes my poor laptop unresponsive if I keep sioyek open for days. I like sioyek but this can easily become a show-stopper. Secondly, while this point goes a bit beyond the scope of this PR, I think embedding a huge library shipped into 3 single files that - for all @ahrm knows - could sneak vulnerabilities without getting noticed in a repo is not a great idea. Furthermore, I think it goes against packagers' intentions as you are introducing a dependency that is outside of the package manager's management. Wouldn't it be better to change the way sioyek imports sqlite3, e.g. either by adding it as a submodule, as it is already done for mupdf, or (probably better) simply expecting it to be installed and accessible from qmake and asking the user to make them discoverable by qmake? My two cents. |
This would be the best solution (it's also the solution Zathura has opted for). |
I second this, we should have a submodule instead and the user should also be allowed to opt for strategic or dynamic linking of sqlite as well. |
The version of SQLite3 currently used by Sioyek suffers from a memory leak in the
sqlite3MemRealloc
function. This PR updates the SQLite3 library to its latest version to address this issue.Valgrind output before the update:
Valgrind output after the update:
Related issue: #693 (This issue can't be closed after merging since there are still memory leaks)