Index: ext/fts2/fts2.c ================================================================== --- ext/fts2/fts2.c +++ ext/fts2/fts2.c @@ -3689,11 +3689,11 @@ dataBufferAppend2(&pWriter->last->data, c, n, pTerm, nTerm); } } /* Free the space used by pWriter, including the linked-list of -** InteriorBlocks. +** InteriorBlocks, and parentWriter, if present. */ static int interiorWriterDestroy(InteriorWriter *pWriter){ InteriorBlock *block = pWriter->first; while( block!=NULL ){ @@ -3700,10 +3700,14 @@ InteriorBlock *b = block; block = block->next; dataBufferDestroy(&b->term); dataBufferDestroy(&b->data); free(b); + } + if( pWriter->parentWriter!=NULL ){ + interiorWriterDestroy(pWriter->parentWriter); + free(pWriter->parentWriter); } SCRAMBLE(pWriter); return SQLITE_OK; } @@ -3841,10 +3845,30 @@ } /****************************************************************/ /* LeafWriter is used to collect terms and associated doclist data ** into leaf blocks in %_segments (see top of file for format info). +** Expected usage is: +** +** LeafWriter writer; +** leafWriterInit(0, 0, &writer); +** while( sorted_terms_left_to_process ){ +** // data is doclist data for that term. +** rc = leafWriterStep(v, &writer, pTerm, nTerm, pData, nData); +** if( rc!=SQLITE_OK ) goto err; +** } +** rc = leafWriterFinalize(v, &writer); +**err: +** leafWriterDestroy(&writer); +** return rc; +** +** leafWriterStep() may write a collected leaf out to %_segments. +** leafWriterFinalize() finishes writing any buffered data and stores +** a root node in %_segdir. leafWriterDestroy() frees all buffers and +** InteriorWriters allocated as part of writing this segment. +** +** TODO(shess) Document leafWriterStepMerge(). */ /* Put terms with data this big in their own block. */ #define STANDALONE_MIN 1024 @@ -4877,10 +4901,11 @@ rc = leafWriterStep(v, &writer, pData[i].pTerm, pData[i].nTerm, dl.pData, dl.nData); dlwDestroy(&dlw); if( rc!=SQLITE_OK ) goto err; } + dataBufferDestroy(&dl); rc = leafWriterFinalize(v, &writer); err: free(pData); leafWriterDestroy(&writer);