double free fix

Wed, 10 Jul 2013 14:38:56 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Jul 2013 14:38:56 +0200
changeset 15
398a7589297f
parent 14
b33629bf4b58
child 16
fa0bcd0444eb

double free fix

src/c2html.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/c2html.c	Wed Jul 10 14:25:41 2013 +0200
     1.2 +++ b/src/c2html.c	Wed Jul 10 14:38:56 2013 +0200
     1.3 @@ -363,14 +363,18 @@
     1.4      inputfile_t *inputfile = readinput(settings.infilename);
     1.5      if (inputfile) {
     1.6        FILE *fout;
     1.7 +      char *line;
     1.8 +      if (settings.highlight) {
     1.9 +        line = (char*) malloc(inputfile->maxlinewidth*64);
    1.10 +      } else {
    1.11 +        line = NULL;
    1.12 +      }
    1.13        if (settings.outfilename) {
    1.14          fout = fopen(settings.outfilename, "w");
    1.15        } else {
    1.16          fout = stdout;
    1.17        }
    1.18        fprintf(fout, "<pre>\n");
    1.19 -      char *line = (char*) malloc(inputfile->maxlinewidth
    1.20 -          * (settings.highlight?64:0));
    1.21        int lnw = lnint(inputfile->count);
    1.22        for (int i = 0 ; i < inputfile->count ; i++) {
    1.23          if (settings.highlight) {
    1.24 @@ -381,7 +385,9 @@
    1.25          fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
    1.26              lnw, i+1, line);
    1.27        }
    1.28 -      free(line);
    1.29 +      if (settings.highlight) {
    1.30 +        free(line);
    1.31 +      }
    1.32        fprintf(fout, "</pre>\n");
    1.33        
    1.34        if (fout != stdout) {

mercurial