fix GC bug in FFI

A foreign procedure's data could get GCed before the procedure
was called, if the procedure is not otherwise reachable.

(Bug found by running tests in GC-stress mode.)
This commit is contained in:
Matthew Flatt 2013-07-06 07:19:42 -06:00
parent 7e27bda44c
commit e3eed89b1d
2 changed files with 10 additions and 0 deletions

View File

@ -3369,6 +3369,11 @@ Scheme_Object *ffi_do_call(int argc, Scheme_Object *argv[], Scheme_Object *self)
nargs, ivals, avalues,
offsets, p);
/* Use `data' to make sure it's kept alive (as far as the GC is concerned)
until the foreign call returns: */
if ((void*)data == (void*)scheme_true)
scheme_signal_error("dummy test suceeded!?");
if (save_errno != 0) save_errno_values(save_errno);
ivals = NULL; /* no need now to hold on to this */
for (i=0; i<nargs; i++) { avalues[i] = NULL; } /* no need for these refs */

View File

@ -2576,6 +2576,11 @@ Scheme_Object *ffi_do_call(int argc, Scheme_Object *argv[], Scheme_Object *self)
nargs, ivals, avalues,
offsets, p);
/* Use `data' to make sure it's kept alive (as far as the GC is concerned)
until the foreign call returns: */
if ((void*)data == (void*)scheme_true)
scheme_signal_error("dummy test suceeded!?");
if (save_errno != 0) save_errno_values(save_errno);
ivals = NULL; /* no need now to hold on to this */
for (i=0; i<nargs; i++) { avalues[i] = NULL; } /* no need for these refs */