Skip to content

Commit c491a19

Browse files
committed
Protect the input object before creating cons cells
Otherwise the garbage collector could delete the object if a GC happens in the cons before it can be protected
1 parent a23f6af commit c491a19

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

inst/include/cpp11/protect.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ inline SEXP protect_sexp(SEXP obj) {
3636
R_PreserveObject(obj);
3737
return obj;
3838
#endif
39+
PROTECT(obj);
3940

4041
// Add a new cell that points to the previous end.
4142
SEXP cell = PROTECT(Rf_cons(protect_list, CDR(protect_list)));
@@ -46,7 +47,7 @@ inline SEXP protect_sexp(SEXP obj) {
4647
SETCAR(CDR(cell), cell);
4748
}
4849

49-
UNPROTECT(1);
50+
UNPROTECT(2);
5051

5152
return cell;
5253
}

0 commit comments

Comments
 (0)