Skip to content

Commit 1b9bb88

Browse files
author
kalibera
committed
PROTECT fix.
git-svn-id: https://svn.r-project.org/R/trunk@87275 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent bb717f7 commit 1b9bb88

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/library/grid/src/path.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
33
* Copyright (C) 2001-3 Paul Murrell
4-
* 2003-2019 The R Core Team
4+
* 2003-2024 The R Core Team
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -47,7 +47,9 @@ SEXP L_fill(SEXP path, SEXP rule)
4747
/* Get the current device
4848
*/
4949
pGEDevDesc dd = getDevice();
50-
currentgp = gridStateElement(dd, GSS_GPAR);
50+
/* currentgp has to be explicitly protected, because resolveGPar()
51+
may change "dd" so that currentgp is no longer protected implicitly */
52+
PROTECT(currentgp = gridStateElement(dd, GSS_GPAR));
5153
PROTECT(resolvedFill = resolveGPar(currentgp, FALSE));
5254
gcontextFromgpar(currentgp, 0, &gc, dd);
5355

@@ -62,7 +64,7 @@ SEXP L_fill(SEXP path, SEXP rule)
6264
SEXP patternRef = getListElement(resolvedFill, "index");
6365
dd->dev->releasePattern(patternRef, dd->dev);
6466
}
65-
UNPROTECT(1); /* resolvedFill */
67+
UNPROTECT(2); /* resolvedFill, currentgp */
6668

6769
GEMode(0, dd);
6870

@@ -77,7 +79,9 @@ SEXP L_fillStroke(SEXP path, SEXP rule)
7779
/* Get the current device
7880
*/
7981
pGEDevDesc dd = getDevice();
80-
currentgp = gridStateElement(dd, GSS_GPAR);
82+
/* currentgp has to be explicitly protected, because resolveGPar()
83+
may change dd so that currentgp is no longer protected implicitly */
84+
PROTECT(currentgp = gridStateElement(dd, GSS_GPAR));
8185
PROTECT(resolvedFill = resolveGPar(currentgp, FALSE));
8286
gcontextFromgpar(currentgp, 0, &gc, dd);
8387

@@ -92,7 +96,7 @@ SEXP L_fillStroke(SEXP path, SEXP rule)
9296
SEXP patternRef = getListElement(resolvedFill, "index");
9397
dd->dev->releasePattern(patternRef, dd->dev);
9498
}
95-
UNPROTECT(1); /* resolvedFill */
99+
UNPROTECT(2); /* resolvedFill, currentgp */
96100

97101
GEMode(0, dd);
98102

0 commit comments

Comments
 (0)