SQLite

Check-in [3cd9b64b96]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3cd9b64b96018f69163ad0be0b5c07dd1be6abc6
User & Date: shess 2006-10-31 18:13:42.000
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: 7ce48000bb 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: 3cd9b64b96 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: ebd44f0b5e user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts2/fts2.c.
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704




3705
3706
3707
3708
3709
3710
3711
    pWriter->last = pWriter->last->next;
  }else{
    dataBufferAppend2(&pWriter->last->data, c, n, pTerm, nTerm);
  }
}

/* Free the space used by pWriter, including the linked-list of
** InteriorBlocks.
*/
static int interiorWriterDestroy(InteriorWriter *pWriter){
  InteriorBlock *block = pWriter->first;

  while( block!=NULL ){
    InteriorBlock *b = block;
    block = block->next;
    dataBufferDestroy(&b->term);
    dataBufferDestroy(&b->data);
    free(b);




  }
  SCRAMBLE(pWriter);
  return SQLITE_OK;
}

/* If pWriter can fit entirely in ROOT_MAX, return it as the root info
** directly, leaving *piEndBlockid unchanged.  Otherwise, flush







|










>
>
>
>







3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
    pWriter->last = pWriter->last->next;
  }else{
    dataBufferAppend2(&pWriter->last->data, c, n, pTerm, nTerm);
  }
}

/* Free the space used by pWriter, including the linked-list of
** InteriorBlocks, and parentWriter, if present.
*/
static int interiorWriterDestroy(InteriorWriter *pWriter){
  InteriorBlock *block = pWriter->first;

  while( block!=NULL ){
    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;
}

/* If pWriter can fit entirely in ROOT_MAX, return it as the root info
** directly, leaving *piEndBlockid unchanged.  Otherwise, flush
3839
3840
3841
3842
3843
3844
3845




















3846
3847
3848
3849
3850
3851
3852
  if( c!=0 ) return c;
  return nReaderTerm - nTerm;
}

/****************************************************************/
/* LeafWriter is used to collect terms and associated doclist data
** into leaf blocks in %_segments (see top of file for format info).




















*/

/* Put terms with data this big in their own block. */
#define STANDALONE_MIN 1024

/* Keep leaf blocks below this size. */
#define LEAF_MAX 2048







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
  if( c!=0 ) return c;
  return nReaderTerm - nTerm;
}

/****************************************************************/
/* 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

/* Keep leaf blocks below this size. */
#define LEAF_MAX 2048
4875
4876
4877
4878
4879
4880
4881

4882
4883
4884
4885
4886
4887
4888
    dlwInit(&dlw, DL_DEFAULT, &dl);
    plwDlwAdd(pData[i].pWriter, &dlw);
    rc = leafWriterStep(v, &writer,
                        pData[i].pTerm, pData[i].nTerm, dl.pData, dl.nData);
    dlwDestroy(&dlw);
    if( rc!=SQLITE_OK ) goto err;
  }

  rc = leafWriterFinalize(v, &writer);

 err:
  free(pData);
  leafWriterDestroy(&writer);
  return rc;
}







>







4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
    dlwInit(&dlw, DL_DEFAULT, &dl);
    plwDlwAdd(pData[i].pWriter, &dlw);
    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);
  return rc;
}