Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.513 2008/09/18 17:34:44 danielk1977 Exp $ +** $Id: btree.c,v 1.514 2008/09/18 18:17:04 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. ** Including a description of file format and an overview of operation. */ @@ -4951,10 +4951,13 @@ rc = ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno); if( rc==SQLITE_OK ){ rc = ptrmapPutOvfl(pNew, 0); } } + + /* Release the reference to the new page. */ + releasePage(pNew); } /* At this point the pPage->nFree variable is not set correctly with ** respect to the content of the page (because it was set to 0 by ** insertCell). So call sqlite3BtreeInitPage() to make sure it is @@ -4970,14 +4973,13 @@ */ pPage->isInit = 0; sqlite3BtreeInitPage(pPage, pPage->pParent); sqlite3PagerUnref(pPage->pParent->pDbPage); - /* Release the reference to the new page and balance the parent page, - ** in case the divider cell inserted caused it to become overfull. + /* If everything else succeeded, balance the parent page, in + ** case the divider cell inserted caused it to become overfull. */ - releasePage(pNew); if( rc==SQLITE_OK ){ rc = balance(pParent, 0); } return rc; }