diff --git a/inst/include/ergm_Rutil.h b/inst/include/ergm_Rutil.h index 24e6fe302..2f62e7128 100644 --- a/inst/include/ergm_Rutil.h +++ b/inst/include/ergm_Rutil.h @@ -30,6 +30,7 @@ static inline SEXP getListElement(SEXP list, const char *str){ } static inline SEXP setListElement(SEXP list, const char *str, SEXP value){ + value = PROTECT(value); SEXP names = getAttrib(list, R_NamesSymbol); for (unsigned int i = 0; i < length(list); i++) @@ -37,6 +38,7 @@ static inline SEXP setListElement(SEXP list, const char *str, SEXP value){ SET_VECTOR_ELT(list, i, value); return value; } + UNPROTECT(1); error("List does not have element '%s' to set.", str); return R_NilValue; }