Fossil

Check-in [4860d9f2]
Login

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

Overview
Comment:The Label list was not properly freed in some cases; looking at the annotate of 'win/Makefile.msc' was triggering the case.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | annotate_noleak
Files: files | file ages | folders
SHA1: 4860d9f23481e46fb99d4e095105fca8905453fd
User & Date: viriketo 2011-09-13 17:18:09
Original Comment: The Label list was not properly freed in some cases; looking at the annotate of 'win/Makefile.msc' was triggering the case.
Context
2011-10-14
16:11
Merging the annotate_noleak changes, about removing an important memory leak in the annotate operation.

It also fixes some blob behaviour in blob.c and content.c.

Update: Removed from trunk. Replaced by the must simpler fix at [9929bab702f99839ee] check-in: 409f370a user: viriketo tags: declined

2011-09-13
17:18
The Label list was not properly freed in some cases; looking at the annotate of 'win/Makefile.msc' was triggering the case. Closed-Leaf check-in: 4860d9f2 user: viriketo tags: annotate_noleak
16:43
Getting in the changes reducing the leak on annotate. In the fossil mailing list, I received only opinions in favour of getting mallocs and frees properly paired, so I think noone will refuse the change. check-in: 7870a89b user: viriketo tags: annotate_noleak
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/diff.c.

715
716
717
718
719
720
721
722

723

724
725
726
727
728
729
730
731
732
...
848
849
850
851
852
853
854

855
856
857
858
859
860
861
...
865
866
867
868
869
870
871

872





873
874
875
876
877
878
879
...
918
919
920
921
922
923
924












925
926
927
928
929
930
931
    struct AnnLine *x = &p->aOrig[lnTo];
    for(j=0; j<p->c.aEdit[i]; j++, lnTo++, x++){
      if( x->zSrc==0 || x->iLevel==iPrevLevel ){
         if (x->zSrc!=0)
         {
           if(--x->zSrc->nref == 0)
           {
               free(x->zSrc->str);

               x->zSrc->prev->next = x->zSrc->next;

               x->zSrc->next->prev = x->zSrc->prev;
               free(x->zSrc);
           }
         }
         x->zSrc = zPName;
         ++zPName->nref;
         x->iLevel = iThisLevel;
      }
    }
................................................................................
    int pid = db_column_int(&q, 0);
    const char *zUuid = db_column_text(&q, 1);
    const char *zDate = db_column_text(&q, 2);
    const char *zUser = db_column_text(&q, 3);
    struct Label *l = fossil_malloc(sizeof(*l));
    l->nref = 0;
    l->next = p->firstLabel;

    if (p->firstLabel)
      p->firstLabel->prev = l;
    if( webLabel ){
      l->str = mprintf(
          "<a href='%s/info/%s' target='infowindow'>%.10s</a> %s %9.9s", 
          g.zTop, zUuid, zUuid, zDate, zUser
      );
................................................................................
    p->firstLabel = l;
    p->nVers++;
    p->azVers = fossil_realloc(p->azVers, p->nVers*sizeof(p->azVers[0]) );
    p->azVers[p->nVers-1] = l;
    content_get(pid, &step);
    annotation_step(p, &step, l);
    if (l->nref == 0)

      free(l->str);





    blob_reset(&step);
  }
  db_finalize(&q);
  free(p->c.aTo);
}

/*
................................................................................
  @ <pre>
  for(i=0; i<ann.nOrig; i++){
    ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0;
    @ %s(ann.aOrig[i].zSrc->str): %h(ann.aOrig[i].z)
  }
  @ </pre>
  style_footer();












}

/*
** COMMAND: annotate
**
** %fossil annotate FILENAME
**







|
>

>

|







 







>







 







>

>
>
>
>
>







 







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







715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
...
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
...
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
    struct AnnLine *x = &p->aOrig[lnTo];
    for(j=0; j<p->c.aEdit[i]; j++, lnTo++, x++){
      if( x->zSrc==0 || x->iLevel==iPrevLevel ){
         if (x->zSrc!=0)
         {
           if(--x->zSrc->nref == 0)
           {
             free(x->zSrc->str);
             if (x->zSrc->prev)
               x->zSrc->prev->next = x->zSrc->next;
             if (x->zSrc->next)
               x->zSrc->next->prev = x->zSrc->prev;
             free(x->zSrc);
           }
         }
         x->zSrc = zPName;
         ++zPName->nref;
         x->iLevel = iThisLevel;
      }
    }
................................................................................
    int pid = db_column_int(&q, 0);
    const char *zUuid = db_column_text(&q, 1);
    const char *zDate = db_column_text(&q, 2);
    const char *zUser = db_column_text(&q, 3);
    struct Label *l = fossil_malloc(sizeof(*l));
    l->nref = 0;
    l->next = p->firstLabel;
    l->prev = 0;
    if (p->firstLabel)
      p->firstLabel->prev = l;
    if( webLabel ){
      l->str = mprintf(
          "<a href='%s/info/%s' target='infowindow'>%.10s</a> %s %9.9s", 
          g.zTop, zUuid, zUuid, zDate, zUser
      );
................................................................................
    p->firstLabel = l;
    p->nVers++;
    p->azVers = fossil_realloc(p->azVers, p->nVers*sizeof(p->azVers[0]) );
    p->azVers[p->nVers-1] = l;
    content_get(pid, &step);
    annotation_step(p, &step, l);
    if (l->nref == 0)
    {
      free(l->str);
      p->firstLabel = l->next;
      if (l->next)
        l->next->prev = 0;
      free(l);
    }
    blob_reset(&step);
  }
  db_finalize(&q);
  free(p->c.aTo);
}

/*
................................................................................
  @ <pre>
  for(i=0; i<ann.nOrig; i++){
    ((char*)ann.aOrig[i].z)[ann.aOrig[i].n] = 0;
    @ %s(ann.aOrig[i].zSrc->str): %h(ann.aOrig[i].z)
  }
  @ </pre>
  style_footer();

  free(ann.azVers);
  free(ann.aOrig);
  blob_reset(&ann.toAnnotate);
  while(ann.firstLabel) {
    struct Label *l;
    l = ann.firstLabel->next;
    assert(ann.firstLabel->nref > 0);
    free(ann.firstLabel->str);
    free(ann.firstLabel);
    ann.firstLabel = l;
  }
}

/*
** COMMAND: annotate
**
** %fossil annotate FILENAME
**