summaryrefslogtreecommitdiff
path: root/libguile/simpos.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2004-04-05 22:45:17 +0000
committerKevin Ryde <user42@zip.com.au>2004-04-05 22:45:17 +0000
commiteac8e0ef86bd2030b103ae2f0ee7ae6e53725663 (patch)
tree501b76710f984d71a660d77640bb995c3599f701 /libguile/simpos.c
parentdec40cd26277b7502029aad2725213fad2ad5560 (diff)
downloadguile-eac8e0ef86bd2030b103ae2f0ee7ae6e53725663.tar.gz
(scm_system_star): Fix execargv memory leak, merge parent
and fork error cases to do this.
Diffstat (limited to 'libguile/simpos.c')
-rw-r--r--libguile/simpos.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/libguile/simpos.c b/libguile/simpos.c
index 5e6005448..356d78673 100644
--- a/libguile/simpos.c
+++ b/libguile/simpos.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003 Free Software
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003, 2004 Free Software
* Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -158,12 +158,26 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
oldquit = scm_sigaction (sigquit, sig_ign, SCM_UNDEFINED);
pid = fork ();
- if (pid == -1)
- SCM_SYSERROR;
- else if (pid)
+ if (pid == 0)
{
- int wait_result;
- int status;
+ /* child */
+ execvp (SCM_STRING_CHARS (SCM_CAR (args)), execargv);
+ scm_remember_upto_here_1 (args);
+ SCM_SYSERROR;
+ /* not reached. */
+ return SCM_BOOL_F;
+ }
+ else
+ {
+ /* parent */
+ int wait_result, status, save_errno;
+
+ save_errno = errno;
+ free (execargv);
+ errno = save_errno;
+ if (pid == -1)
+ SCM_SYSERROR;
+
SCM_SYSCALL (wait_result = waitpid (pid, &status, 0));
if (wait_result == -1) SCM_SYSERROR;
scm_sigaction (sigint, SCM_CAR (oldint), SCM_CDR (oldint));
@@ -171,14 +185,6 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
scm_remember_upto_here_2 (oldint, oldquit);
return SCM_MAKINUM (0L + status);
}
- else
- {
- execvp (SCM_STRING_CHARS (SCM_CAR (args)), execargv);
- scm_remember_upto_here_1 (args);
- SCM_SYSERROR;
- /* not reached. */
- return SCM_BOOL_F;
- }
}
else
SCM_WRONG_TYPE_ARG (1, SCM_CAR (args));