Fix memory leakage introduced into print_aligned_text by 8.4 changes
authorTom Lane <[email protected]>
Sat, 30 Jan 2010 18:59:51 +0000 (18:59 +0000)
committerTom Lane <[email protected]>
Sat, 30 Jan 2010 18:59:51 +0000 (18:59 +0000)
(failure to free col_lineptrs[] array elements) and exacerbated in the
current devel cycle (failure to free "wrap").  This resulted in moderate
bloat of psql over long script runs.  Noted while testing bug #5302,
although what the reporter was complaining of was backend-side leakage.

src/bin/psql/print.c

index 4d05794e58316b37b706d0af9cd730c60631d206..70da660bb09a248ade4046d8b6d093c1c9654b3d 100644 (file)
@@ -1047,6 +1047,11 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
    }
 
    /* clean up */
+   for (i = 0; i < col_count; i++)
+   {
+       free(col_lineptrs[i]);
+       free(format_buf[i]);
+   }
    free(width_header);
    free(width_average);
    free(max_width);
@@ -1055,11 +1060,10 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
    free(curr_nl_line);
    free(col_lineptrs);
    free(max_bytes);
+   free(format_buf);
    free(header_done);
    free(bytes_output);
-   for (i = 0; i < col_count; i++)
-       free(format_buf[i]);
-   free(format_buf);
+   free(wrap);
 
    if (is_pager)
        ClosePager(fout);