# HG changeset patch # User Mike Becker # Date 1373459936 -7200 # Node ID 398a7589297f1fe771b136211f7330cfca26f50a # Parent b33629bf4b5806f8348c7f4efceb44f47cde4639 double free fix diff -r b33629bf4b58 -r 398a7589297f src/c2html.c --- 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, "
\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, "%*d: %s",
             lnw, i+1, line);
       }
-      free(line);
+      if (settings.highlight) {
+        free(line);
+      }
       fprintf(fout, "
\n"); if (fout != stdout) {