Skip to content

Commit dadb358

Browse files
author
Ethan A Merritt
committed
prevent double-free error caused by redundant contour label font
The font used for contour labels is taken from 'set cntrlabel font'. For some reason providing an explicit font in the splot command causes a double-free during cleanup. Since this font would not be used anyway, clear it before it can cause any damage. Bug #2154
1 parent 2d86ea9 commit dadb358

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/graph3d.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ do_3dplot(
14391439
free(thiscontour_label);
14401440
thiscontour_label = gp_strdup(c);
14411441
}
1442-
/* cntr3d_lines(cntrs, &thiscontour_lp_properties); */
14431442
cntr3d_labels(cntrs, thiscontour_label, this_plot->labels);
14441443
break;
14451444

@@ -2153,6 +2152,7 @@ cntr3d_labels(struct gnuplot_contours *cntr, char *level_text, struct text_label
21532152
continue;
21542153
map3d_xy(cntr->coords[i].x, cntr->coords[i].y, base_z, &x, &y);
21552154
label->text = level_text;
2155+
label->font = clabel_font;
21562156
if (hidden3d) {
21572157
map3d_xyz(cntr->coords[i].x, cntr->coords[i].y, base_z, &v);
21582158
v.real_z = cntr->coords[i].z;
@@ -2162,6 +2162,7 @@ cntr3d_labels(struct gnuplot_contours *cntr, char *level_text, struct text_label
21622162
write_label(x, y, label);
21632163
}
21642164
label->text = NULL; /* Otherwise someone will try to free it */
2165+
label->font = NULL;
21652166
}
21662167
}
21672168
}

src/plot3d.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,14 @@ eval_3dplots()
20202020
this_plot->lp_properties.p_size = 1;
20212021
}
20222022

2023+
/* FIXME: Leaving an explicit font in the label style for contour */
2024+
/* labels causes a double-free segfault. Clear it preemptively. */
2025+
if (this_plot->plot_style == LABELPOINTS
2026+
&& (draw_contour && !this_plot->opt_out_of_contours)) {
2027+
free(this_plot->labels->font);
2028+
this_plot->labels->font = NULL;
2029+
}
2030+
20232031
if (crnt_param == 0
20242032
&& this_plot->plot_style != PM3DSURFACE
20252033
/* don't increment the default line/point properties if
@@ -2695,8 +2703,6 @@ parametric_3dfixup(struct surface_points *start_plot, int *plot_num)
26952703
static void load_contour_label_options (struct text_label *contour_label)
26962704
{
26972705
struct lp_style_type *lp = &(contour_label->lp_properties);
2698-
if (!contour_label->font)
2699-
contour_label->font = gp_strdup(clabel_font);
27002706
lp->p_interval = clabel_interval;
27012707
lp->flags |= LP_SHOW_POINTS;
27022708
lp_parse(lp, LP_ADHOC, TRUE);

0 commit comments

Comments
 (0)