Skip to content

Commit 799d2b5

Browse files
committed
unqlite: bug fix, assgin the pEngine->pHeader when get the page one
The pEngine->pHeader is assgined at the first load of database, unqlite_commit() will release all the pages in pager_commit_phase1(), also the page one (header page) is released, then the header page memory was freed, so the pEngine->pHeader point to a invalid address. In some situations that use the pEngine->pHeader, system crash. This commit assgin the pEngine->pHeader every time get the page one to solve this problem. Release all the pages trace: 0 sched_backtrace 1 pager_release_page.isra.0 2 pager_commit_phase1 3 unqlite_commit 4 kvdb_server Crash trace: 0 pager_shared_lock (pPager=0x0) at ../../../../external/unqlite/unqlite/unqlite.c:56873 1 unqlitePagerBegin (pPager=0x0) at ../../../../external/unqlite/unqlite/unqlite.c:56947 2 unqlitePageWrite (pMyPage=0x341c6ff0) at ../../../../external/unqlite/unqlite/unqlite.c:57584 3 unqliteKvIopageWrite (pPage=0x341c6ff0) at ../../../../external/unqlite/unqlite/unqlite.c:58071 4 0x0c239e32 in lhSplit (pRetry=<synthetic pointer>, pTarget=0x341c12d0) at ../../../../external/unqlite/unqlite/unqlite.c:51066 5 lhRecordInstall (nDataLen=6, pData=0x341b9233, nKeyLen=24, pKey=0x341b921b, nHash=1585931874, pPage=0x341c12d0) at ../../../../external/unqlite/unqlite/unqlite.c:51109 6 lh_record_insert (is_append=0, nDataLen=6, pData=0x341b9233, nKeyLen=24, pKey=0x341b921b, pKv=0x3419a56c) at ../../../../external/unqlite/unqlite/unqlite.c:51200 7 lh_record_insert (pKv=0x3419a56c, pKey=0x341b921b, nKeyLen=24, pData=0x341b9233, nDataLen=nDataLen@entry=6, is_append=is_append@entry=0) at ../../../../external/unqlite/unqlite/unqlite.c:51125 8 0x0c23a57a in lhash_kv_replace (pKv=<optimized out>, pKey=<optimized out>, nKeyLen=<optimized out>, pData=<optimized out>, nDataLen=6) at ../../../../external/unqlite/unqlite/unqlite.c:51230 9 0x0c3e78c0 in unqlite_kv_store (nDataLen=6, pData=0x341b9233, nKeyLen=24, pKey=0x341b921b, pDb=0x341c0910) at ../../../../external/unqlite/unqlite/unqlite.c:5490 10 kvdb_set (db=db@entry=0x341b9088, key=key@entry=0x341b921b "persist.nightmode.light", key_len=key_len@entry=24, value=value@entry=0x341b9233 "night", val_len=val_len@entry=6, force=force@entry=false) at ../../../../frameworks/utils/kvdb/server.c:132 11 0x0c3e7f54 in kvdb_client (fd=7, kv=0x341b9080) at ../../../../frameworks/utils/kvdb/server.c:596 12 kvdb_server (kv=0x341b9080) at ../../../../frameworks/utils/kvdb/server.c:699 13 kvdbd_main (argc=<optimized out>, argv=<optimized out>) at ../../../../frameworks/utils/kvdb/server.c:737 14 0x0c19143c in nxtask_startup (argv=<optimized out>, argc=<optimized out>, entrypt=<optimized out>) at ../../../libs/libc/sched/task_startup.c:70 15 nxtask_start () at ../../../sched/task/task_start.c:134 Signed-off-by: wangbowen6 <[email protected]>
1 parent 9c4cd30 commit 799d2b5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

unqlite.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49654,7 +49654,7 @@ static int lhRecordLookup(
4965449654
sxu32 nHash;
4965549655
int rc;
4965649656
/* Acquire the first page (hash Header) so that everything gets loaded autmatically */
49657-
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,0);
49657+
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,&pEngine->pHeader);
4965849658
if( rc != UNQLITE_OK ){
4965949659
return rc;
4966049660
}
@@ -51094,7 +51094,7 @@ static int lh_record_insert(
5109451094
int rc;
5109551095

5109651096
/* Acquire the first page (DB hash Header) so that everything gets loaded automatically */
51097-
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,0);
51097+
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,&pEngine->pHeader);
5109851098
if( rc != UNQLITE_OK ){
5109951099
return rc;
5110051100
}
@@ -51530,7 +51530,7 @@ static int lhCursorFirst(unqlite_kv_cursor *pCursor)
5153051530
int rc;
5153151531
if( pCur->is_first ){
5153251532
/* Read the database header first */
51533-
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,0);
51533+
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,&pEngine->pHeader);
5153451534
if( rc != UNQLITE_OK ){
5153551535
return rc;
5153651536
}
@@ -51552,7 +51552,7 @@ static int lhCursorLast(unqlite_kv_cursor *pCursor)
5155251552
int rc;
5155351553
if( pCur->is_first ){
5155451554
/* Read the database header first */
51555-
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,0);
51555+
rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,1,&pEngine->pHeader);
5155651556
if( rc != UNQLITE_OK ){
5155751557
return rc;
5155851558
}

0 commit comments

Comments
 (0)