/ Check-in [3cd9b64b]
Login

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

Overview
Comment:Fix a pair of memory leaks. These were turned up by running valgrind memcheck with various 10k doc insert, update, delete, and query tests. (CVS 3497)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3cd9b64b96018f69163ad0be0b5c07dd1be6abc6
User & Date: shess 2006-10-31 18:13:42
Context
2006-10-31
21:16
Change the default prefix for temporary files so that it no longer contains the text "sqlite". In this way, perhaps we will not get so many false bug reports such as ticket #2049, #1989, and #1841. (CVS 3498) check-in: 7ce48000 user: drh tags: trunk
18:13
Fix a pair of memory leaks. These were turned up by running valgrind memcheck with various 10k doc insert, update, delete, and query tests. (CVS 3497) check-in: 3cd9b64b user: shess tags: trunk
18:08
Make the command-line shell ".dump" command more resilient in the face of database corruption. (CVS 3496) check-in: ebd44f0b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts2/fts2.c.

  3687   3687       pWriter->last = pWriter->last->next;
  3688   3688     }else{
  3689   3689       dataBufferAppend2(&pWriter->last->data, c, n, pTerm, nTerm);
  3690   3690     }
  3691   3691   }
  3692   3692   
  3693   3693   /* Free the space used by pWriter, including the linked-list of
  3694         -** InteriorBlocks.
         3694  +** InteriorBlocks, and parentWriter, if present.
  3695   3695   */
  3696   3696   static int interiorWriterDestroy(InteriorWriter *pWriter){
  3697   3697     InteriorBlock *block = pWriter->first;
  3698   3698   
  3699   3699     while( block!=NULL ){
  3700   3700       InteriorBlock *b = block;
  3701   3701       block = block->next;
  3702   3702       dataBufferDestroy(&b->term);
  3703   3703       dataBufferDestroy(&b->data);
  3704   3704       free(b);
         3705  +  }
         3706  +  if( pWriter->parentWriter!=NULL ){
         3707  +    interiorWriterDestroy(pWriter->parentWriter);
         3708  +    free(pWriter->parentWriter);
  3705   3709     }
  3706   3710     SCRAMBLE(pWriter);
  3707   3711     return SQLITE_OK;
  3708   3712   }
  3709   3713   
  3710   3714   /* If pWriter can fit entirely in ROOT_MAX, return it as the root info
  3711   3715   ** directly, leaving *piEndBlockid unchanged.  Otherwise, flush
................................................................................
  3839   3843     if( c!=0 ) return c;
  3840   3844     return nReaderTerm - nTerm;
  3841   3845   }
  3842   3846   
  3843   3847   /****************************************************************/
  3844   3848   /* LeafWriter is used to collect terms and associated doclist data
  3845   3849   ** into leaf blocks in %_segments (see top of file for format info).
         3850  +** Expected usage is:
         3851  +**
         3852  +** LeafWriter writer;
         3853  +** leafWriterInit(0, 0, &writer);
         3854  +** while( sorted_terms_left_to_process ){
         3855  +**   // data is doclist data for that term.
         3856  +**   rc = leafWriterStep(v, &writer, pTerm, nTerm, pData, nData);
         3857  +**   if( rc!=SQLITE_OK ) goto err;
         3858  +** }
         3859  +** rc = leafWriterFinalize(v, &writer);
         3860  +**err:
         3861  +** leafWriterDestroy(&writer);
         3862  +** return rc;
         3863  +**
         3864  +** leafWriterStep() may write a collected leaf out to %_segments.
         3865  +** leafWriterFinalize() finishes writing any buffered data and stores
         3866  +** a root node in %_segdir.  leafWriterDestroy() frees all buffers and
         3867  +** InteriorWriters allocated as part of writing this segment.
         3868  +**
         3869  +** TODO(shess) Document leafWriterStepMerge().
  3846   3870   */
  3847   3871   
  3848   3872   /* Put terms with data this big in their own block. */
  3849   3873   #define STANDALONE_MIN 1024
  3850   3874   
  3851   3875   /* Keep leaf blocks below this size. */
  3852   3876   #define LEAF_MAX 2048
................................................................................
  4875   4899       dlwInit(&dlw, DL_DEFAULT, &dl);
  4876   4900       plwDlwAdd(pData[i].pWriter, &dlw);
  4877   4901       rc = leafWriterStep(v, &writer,
  4878   4902                           pData[i].pTerm, pData[i].nTerm, dl.pData, dl.nData);
  4879   4903       dlwDestroy(&dlw);
  4880   4904       if( rc!=SQLITE_OK ) goto err;
  4881   4905     }
         4906  +  dataBufferDestroy(&dl);
  4882   4907     rc = leafWriterFinalize(v, &writer);
  4883   4908   
  4884   4909    err:
  4885   4910     free(pData);
  4886   4911     leafWriterDestroy(&writer);
  4887   4912     return rc;
  4888   4913   }