diff --git a/src/gsumm.c b/src/gsumm.c index 7607f4258..16cc228a3 100644 --- a/src/gsumm.c +++ b/src/gsumm.c @@ -594,8 +594,9 @@ SEXP gmean(SEXP x, SEXP narmArg) x = PROTECT(coerceVector(x, REALSXP)); protecti++; case REALSXP: { if (INHERITS(x, char_integer64)) { - x = PROTECT(coerceAs(x, /*as=*/PROTECT(ScalarReal(1)), /*copyArg=*/ScalarLogical(TRUE))); protecti++; - UNPROTECT(1); // as= input to coerceAs() + SEXP as = PROTECT(ScalarReal(1)); + x = PROTECT(coerceAs(x, as, /*copyArg=*/ScalarLogical(TRUE))); protecti++; + UNPROTECT(2); PROTECT(x); // PROTECT() is stack-based, UNPROTECT() back to 'as' then PROTECT() 'x' again } const double *restrict gx = gather(x, &anyNA); ans = PROTECT(allocVector(REALSXP, ngrp)); protecti++;