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
--- a/src/c2html.c	Wed Jul 10 14:25:41 2013 +0200
+++ b/src/c2html.c	Wed Jul 10 14:38:56 2013 +0200
@@ -363,14 +363,18 @@
     inputfile_t *inputfile = readinput(settings.infilename);
     if (inputfile) {
       FILE *fout;
+      char *line;
+      if (settings.highlight) {
+        line = (char*) malloc(inputfile->maxlinewidth*64);
+      } else {
+        line = NULL;
+      }
       if (settings.outfilename) {
         fout = fopen(settings.outfilename, "w");
       } else {
         fout = stdout;
       }
       fprintf(fout, "<pre>\n");
-      char *line = (char*) malloc(inputfile->maxlinewidth
-          * (settings.highlight?64:0));
       int lnw = lnint(inputfile->count);
       for (int i = 0 ; i < inputfile->count ; i++) {
         if (settings.highlight) {
@@ -381,7 +385,9 @@
         fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
             lnw, i+1, line);
       }
-      free(line);
+      if (settings.highlight) {
+        free(line);
+      }
       fprintf(fout, "</pre>\n");
       
       if (fout != stdout) {

mercurial