Skip to content

Commit d5e8186

Browse files
author
sfeam
committed
do not call cairo_destroy() on program exit
1 parent e06ef4a commit d5e8186

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2017-09-19 Ethan A Merritt <[email protected]>
2+
3+
* term/cairo.trm (cairotrm_init cairotrm_reset): Valgrind complained
4+
that calling cairo_destroy(plot.cr) on exit triggered multiple reads
5+
of previously-freed data. It seems preferable to not call it on exit.
6+
It does make sense to call it if the terminal has been closed and then
7+
reopened. So we fix the ordering of code in cairotrm_init that
8+
frees the old plot.cr before reinitializing a new one.
9+
110
2017-09-18 Ethan A Merritt <[email protected]>
211

312
* src/datafile.c (f_columnhead df_set_key_title) src/datafile.h

term/cairo.trm

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Hello, Emacs: this is -*-C-*- !
2-
* $Id: cairo.trm,v 1.79 2017-05-07 19:20:52 sfeam Exp $
2+
* $Id: cairo.trm,v 1.80 2017-09-19 20:15:10 sfeam Exp $
33
*/
44

55
/* GNUPLOT - cairo.trm */
@@ -653,16 +653,16 @@ void cairotrm_init()
653653
if (ISCAIROLATEX && !outstr)
654654
os_error(c_token, "cairolatex terminal cannot write to standard output");
655655

656+
/* We no longer do this in cairotrm_reset() */
657+
if (plot.cr)
658+
cairo_destroy(plot.cr);
659+
656660
/* initialisations */
657661
gp_cairo_initialize_plot(&plot);
658662
plot.device_xmax = (double) cairo_params->width;
659663
plot.device_ymax = (double) cairo_params->height;
660664
plot.dashlength = cairo_params->dash_length;
661665

662-
/* is supposed to be done in cairotrm_reset */
663-
if ( plot.cr )
664-
cairo_destroy(plot.cr);
665-
666666
if (!strcmp(term->name,"pdfcairo")) {
667667
/* Output can either be a file or stdout */
668668
#ifndef _WIN32
@@ -973,8 +973,13 @@ void cairotrm_text()
973973
/* sent when gnuplot exits and when the terminal or the output change.*/
974974
void cairotrm_reset()
975975
{
976-
/* finish the document */
977-
cairo_destroy(plot.cr);
976+
/* Sep 2017
977+
* valgrind complains that this triggers reads of already-freed data.
978+
* It is unclear whether that is a real problem, but it is also unclear
979+
* that anything is gained by explicit cleanup when we are about to exit.
980+
* Let's try skipping it and see if anyone notices.
981+
*/
982+
/* cairo_destroy(plot.cr); */
978983

979984
#ifdef PSLATEX_DRIVER
980985
/* finish latex output */

0 commit comments

Comments
 (0)