From 369bc08f2e653fb3279a817eae255cef096b215a Mon Sep 17 00:00:00 2001 From: sperber Date: Sun, 27 Jan 2002 20:20:09 +0000 Subject: [PATCH] GC protection fix for waitpid. Note that there are probably more bugs similar to this one. --- scsh/syscalls1.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scsh/syscalls1.c b/scsh/syscalls1.c index 8ed3f2a..0207351 100644 --- a/scsh/syscalls1.c +++ b/scsh/syscalls1.c @@ -61,13 +61,26 @@ s48_value wait_pid(s48_value s48_pid, s48_value s48_flags) pid_t pid = (pid_t) s48_extract_integer (s48_pid); int flags = s48_extract_integer (s48_flags); pid_t result_pid; + s48_value sch_result_pid = S48_UNSPECIFIC; + s48_value sch_status = S48_UNSPECIFIC; + s48_value sch_status_list = S48_UNSPECIFIC; + s48_value sch_retval = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(4); + + S48_GC_PROTECT_4(sch_result_pid, sch_status, sch_status_list, sch_retval); result_pid = waitpid(pid, &status, flags); if (result_pid == -1) - s48_raise_os_error_2 (errno, s48_pid, s48_flags); - return s48_cons (s48_enter_integer (result_pid), - s48_cons (s48_enter_integer (status), - S48_NULL)); + s48_raise_os_error_2 (errno, s48_pid, s48_flags); + + sch_result_pid = s48_enter_integer (result_pid); + sch_status = s48_enter_integer (status); + sch_status_list = s48_cons (sch_status, S48_NULL); + sch_retval = s48_cons (sch_result_pid, sch_status_list); + + S48_GC_UNPROTECT(); + + return sch_retval; }