SQLite

Check-in [9285899120]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a page-cache reference leak in the btree balancer when there is a corrupt database.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | deferred-free-space
Files: files | file ages | folders
SHA3-256: 9285899120dec24ff2944431ad455d7ae217ef408ae2f1a3e7bdfb897099028c
User & Date: drh 2019-02-09 22:33:44.636
Context
2019-02-11
12:51
Updates to a comment to keep it in alignment to the changes on this branch. (check-in: 7499f74351 user: drh tags: deferred-free-space)
2019-02-09
22:33
Fix a page-cache reference leak in the btree balancer when there is a corrupt database. (check-in: 9285899120 user: drh tags: deferred-free-space)
21:06
Defer computing the MemPage.nFree value of an in-memory btree page until it is actually needed, since for many pages it is never needed. This checkin works sufficiently to prove the concept, but still has issues with exception handling. (check-in: 1d43ee4000 user: drh tags: deferred-free-space)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btree.c.
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558







7559
7560
7561
7562
7563
7564
7565
    pRight = &pParent->aData[pParent->hdrOffset+8];
  }else{
    pRight = findCell(pParent, i+nxDiv-pParent->nOverflow);
  }
  pgno = get4byte(pRight);
  while( 1 ){
    rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
    if( rc==0 && apOld[i]->nFree<0 ){
      rc = btreeComputeFreeSpace(apOld[i]);
    }
    if( rc ){
      memset(apOld, 0, (i+1)*sizeof(MemPage*));
      goto balance_cleanup;







    }
    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
    if( (i--)==0 ) break;

    if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
      apDiv[i] = pParent->apOvfl[0];
      pgno = get4byte(apDiv[i]);







<
<
<



>
>
>
>
>
>
>







7546
7547
7548
7549
7550
7551
7552



7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
    pRight = &pParent->aData[pParent->hdrOffset+8];
  }else{
    pRight = findCell(pParent, i+nxDiv-pParent->nOverflow);
  }
  pgno = get4byte(pRight);
  while( 1 ){
    rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);



    if( rc ){
      memset(apOld, 0, (i+1)*sizeof(MemPage*));
      goto balance_cleanup;
    }
    if( apOld[i]->nFree<0 ){
      rc = btreeComputeFreeSpace(apOld[i]);
      if( rc ){
        memset(apOld, 0, (i)*sizeof(MemPage*));
        goto balance_cleanup;
      }
    }
    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
    if( (i--)==0 ) break;

    if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
      apDiv[i] = pParent->apOvfl[0];
      pgno = get4byte(apDiv[i]);